LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-27-2007, 12:23 AM   #1
hiwa
LQ Newbie
 
Registered: Oct 2004
Location: Japan
Distribution: RHL9
Posts: 10

Rep: Reputation: 0
String comparison in while [ ... ] condition


Code:
# if user input is a 'y', repeat the process
a="y"
while [ $a=y ]
do
 read a
 echo "Bang! $a"
done
In the above script,
while [ $a=y ]
while [ $a="y" ]
while [ "$a"=y ]
while [ "$a"="y" ]
while [ $a='y' ]
etc., etc. all fails. I'm completely stuck.

What could be the correct syntax and why?
 
Old 05-27-2007, 12:53 AM   #2
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
It needs to be:
Code:
while [ "$a" = "y" ]
Apparently bash requires white spaces around the equal sign.
 
Old 05-27-2007, 01:17 AM   #3
hiwa
LQ Newbie
 
Registered: Oct 2004
Location: Japan
Distribution: RHL9
Posts: 10

Original Poster
Rep: Reputation: 0
That works. Thanks!
It tormented me more than a half day today!
 
Old 05-27-2007, 02:05 AM   #4
daihard
Member
 
Registered: Jul 2003
Location: Seattle, WA
Distribution: Kubuntu 14.04 LTS
Posts: 915

Rep: Reputation: 34
Quote:
Originally Posted by hiwa
That works. Thanks!
It tormented me more than a half day today!
Glad it helped. Otsukare-sama.
 
  


Reply



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
String comparison algorithm MicahCarrick Programming 4 04-11-2006 01:26 AM
Comparison between character and hexadecimal string.. vishalbutte Programming 2 03-05-2006 07:59 PM
bash string comparison noir911 Programming 1 01-25-2006 06:37 PM
Perl String comparison Xris718 Linux - General 5 04-01-2005 01:59 PM
perl string comparison problem AM1SHFURN1TURE Programming 3 03-06-2005 10:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:02 PM.

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