LinuxQuestions.org
Help answer threads with 0 replies.
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, 08:31 AM   #1
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
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, 09:51 AM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
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, 10:36 AM   #3
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
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 09:55 AM
Compare first characters of a string in UNIX shell loopoo Linux - Newbie 8 12-11-2006 12:35 PM
how to format the output of a command and save it into a string variable gn00kie Programming 1 07-15-2006 04:04 AM
compare string in SQL hus Programming 9 04-27-2005 11:17 AM
compare string in C++ danxl Programming 3 11-02-2003 03:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:44 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration