简体   繁体   中英

How to write shell script?

I want to write a shell that runs until something is written to a file (by another process). I have written this:

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

but I get

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

This line:

while [$DONE -eq 0]

Needs spaces around the square brackets:

while [ $DONE -eq 0 ]

As does this one:

if [$LINE -neq ""]; then

Like this:

if [ $LINE -neq "" ]; then   

It helps when you know that \\[ is a command . See Why should be there a space after '[' and before ']' in the Bash Script for an explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM