【发布时间】:2011-12-16 21:29:23
【问题描述】:
这是我的 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,因为它不喜欢当前的方法。
【问题讨论】:
标签: bash shell while-loop if-statement