这是我的 foobar.sh 的代码:
!#/bin/bash
while [ 1 ]
do
pid=`ps -ef | grep "mylittleprogram" | grep -v grep | awk ' {print $2}'`
echo $pid
if [ "$pid"="" ]
then
echo "Process has ended lets get this show on the road..."
exit
else
echo "Process has not ended yet"
fi
sleep 6
done
我基本上是在运行一个无限循环,它会在受监视的进程结束后执行命令 X,但我最终在脚本循环时收到以下消息:
./foobar.sh: line 7: [: missing `]'
Process has not ended yet
有没有办法让脚本接受零反馈将触发我的“Then”语句并执行命令 X,因为它不喜欢当前的方法。
最佳答案
代替
if [ "$pid"="" ]
请试试
if [ "$pid" = "" ]
=
周围的空格很重要。
你也可以试试
if [ -z "$pid" ]
关于bash - 带有空白/空 grep 的 Do 语句返回时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7922854/