1

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
1
  • 1
    [$DONE -eq 0] => [ $DONE -eq 0 ], btw you can use the test program in place of the [ command. Commented Feb 28, 2013 at 8:38

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.