Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

My script returns an error when it doesn't like the input

I have a script which assigns the output of a shell command to a string, for later comparison.

The command typically outputs either "Idle" or
"Uploading 1 file (102.8 KB/sec, 1 min left)"

I use a test:

while test $status != 'Idle'

However, when the string is not equal to 'Idle' it crashes, possibly because of the unusual characters such as / and ( etc. in the alternative output.

Is it possible to compare or even prepare the string before comparison so that my script doesn't crash? Or is shell scripting limited in this way, in which case I should be using a different language?

Here is the script in case it makes things clearer. It's purpose is to start dropbox, allow it's running while it is performing any action, but exiting if everything is already up to date.
[code]
#! /bin/sh
dropbox start

status=$(dropbox status)

while test $status != 'Idle'
do
echo "Working"
status=$(dropbox status)
done

echo "
Idle again.. exiting"
dropbox stop[/code]
Sign In or Register to comment.