LINUX programming

Moderators: ITA
Number of threads: 1347
Number of posts: 2935

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
My script returns an error when it doesn't like the input Posted by jarlath on 31 Oct 2009 at 4:24 PM
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.
#! /bin/sh
dropbox start

status=$(dropbox status)

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

echo "\nIdle again.. exiting"
dropbox stop




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.