我的代码:
$test =$(ps -ef |grep -c "java")
echo "$test"
这给了我错误:
root@test:~# ./restart.sh
./restart.sh: line 1: =4: command not found
有4个Java进程正在运行。
尝试:
test=$(ps -ef |grep -c "java")
echo "$test"
我认为您只需要删除第一个$符号即可。
要将任何shell命令的输出分配给bash中的变量,请使用以下命令替换语法:
var=$(command-name-here)
var=$(command-name-here arg1)
var=$(/path/to/command)
var=$(/path/to/command arg1 arg2)
编辑:“不要在等号之前或之后放置任何空格”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句