如何编写shell脚本?

时间:2013-02-28 08:35:55

标签: linux shell unix

我想编写一个运行的shell,直到将某些内容写入文件(由另一个进程)。我写了这个:

PID_FILE=log.txt
DONE=0
while [$DONE -eq 0]
do 
    cat $PID_FILE | while read LINE 
    do
    if [$LINE -neq ""]; then    
        echo "Do stuff here"
        $DONE=1
    fi  
    done
done    
echo "DONE"
echo "">$PID_FILE

但我得到

test.sh: 3: test.sh: [0: not found
DONE

1 个答案:

答案 0 :(得分:6)

这一行:

while [$DONE -eq 0]

方括号周围需要空格:

while [ $DONE -eq 0 ]

就像这一样:

if [$LINE -neq ""]; then

像这样:

if [ $LINE -neq "" ]; then   

It helps when you know that \[ is a command.有关解释,请参阅Why should be there a space after '[' and before ']' in the Bash Script