LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-31-2006, 07:31 AM   #1
daYz
Member
 
Registered: Nov 2003
Distribution: Debian
Posts: 164

Rep: Reputation: 30
How to compare the output of a command with a string?


Hi,

I want to run a while loop when the output of a command is not equal to a certain string. I cannot determine how that can be done.

Can someone show me the correct way of doing this?

Thanks! And a happy new year!

Ben
 
Old 12-31-2006, 08:51 AM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
Read 'man bash'. So:
while [ "$( command )" != "string" ]; do something; done;
$( ) will substitute output of what is inside.
"" will stop word splitting.
[ is builtin that tests some conditions, like != for strings.
 
Old 12-31-2006, 09:36 AM   #3
daYz
Member
 
Registered: Nov 2003
Distribution: Debian
Posts: 164

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by raskin
Read 'man bash'. So:
while [ "$( command )" != "string" ]; do something; done;
$( ) will substitute output of what is inside.
"" will stop word splitting.
[ is builtin that tests some conditions, like != for strings.
Raskin thank you very much. I works very well.

I can always appreciate the help from people on boards so much.

Happy new year!

Ben
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
command to compare lines in a file? wgato Linux - Newbie 4 12-17-2006 08:55 AM
Compare first characters of a string in UNIX shell loopoo Linux - Newbie 8 12-11-2006 11:35 AM
how to format the output of a command and save it into a string variable gn00kie Programming 1 07-15-2006 03:04 AM
compare string in SQL hus Programming 9 04-27-2005 10:17 AM
compare string in C++ danxl Programming 3 11-02-2003 02:14 PM


All times are GMT -5. The time now is 03:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration