bash 如何在linux shell中存储nproc返回的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21733118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to store value returned by nproc in linux shell?
提问by Kyanite
I'm trying to store the number of CPUs in a variable for a linux bash shell. I know nproc returns the number of CPUs however I can't seem to store the value returned in a variable.
我正在尝试将 CPU 数量存储在 linux bash shell 的变量中。我知道 nproc 返回 CPU 的数量,但是我似乎无法将返回的值存储在变量中。
I'm sure it's a simple solution so any help would be appreciated.
我确定这是一个简单的解决方案,因此我们将不胜感激。
Thanks
谢谢
回答by Малъ Скрылевъ
Just use nested call to nproc:
只需使用嵌套调用nproc:
$ NPROC=$(nproc)
echo $NPROC
1