我正在尝试运行以下shell脚本 test.sh
test.sh
$service=$1 $count=`ps -ef |grep -i "$service" |grep -v grep | wc -l` echo "$count"
命令: sh test.sh abcde
sh test.sh abcde
我希望脚本输出0,但它给了我1。
PS:我将从一个php文件中使用shell\u exec运行这个脚本,脚本的输入将是来自php文件的数组元素
你得到 1 因为 ps -ef 包括命令
1
ps -ef
当你这样做的时候,这是匹配的 grep -i "abcde" grep ,所以改变
grep -i "abcde"
grep
grep -v grep
到
grep -E -v 'grep|test\.sh'