0
#!/bin/sh
SUCCESS=0 
java -jar sbc.jar &
while [ true ];
do
echo "sleeping"
sleep 5
echo "again"
tail -1 ~/NetBeansProjects/xyz/dist/newlog.log | grep -q "[INFO ] - Stream closed"
if  [ $? = 1 ]
then
echo " entered if "
java -jar sbc.jar &
else 
echo " did not if "
fi
done

I want to use a better variable than $? to store the result of the previous line because I may need it more than once. The script is intended to check the last line of the file newlog.log for a particualr string and then start sbc.jar again because the string confirms that the program has stopped.

1 Answer 1

1

Store it in another variable:

...
tail -1 ~/NetBeansProjects/xyz/dist/newlog.log | grep -q "[INFO ] - Stream closed"
RES=$?
if  [ $RES = 1 ]
...
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I was giving a space after RES earlier which was making it an unknown variable. Whitespaces are an issue with shell scripting :P . Thanks a lot :)
You're welcome. I often made that mistake. The other most common one for me was not leaving a space after [ and before ] for conditionals. Please accept this answer to save other people time.
that I figured out yesterday :D
I would have accepted it. It was showing 5 minutes are too less to accept. Done now! :)

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.