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

Howdy, Stranger!

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

Categories

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.