LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-28-2004, 10:19 AM   #1
ner
Member
 
Registered: Oct 2003
Posts: 40

Rep: Reputation: 15
Simple shell script is driving me crazy


Hi,
I am trying to write a shell script using if .. then.. else.. should be fairly easy, but my script always outputs else function. For example the script bellow always outputs "Shame on you!!" even when the ANSWER is yes:

#!/bin/bash
echo "Are you a good person?"
read ANSWER
if [$ANSWER="yes"]; then
echo "Good for you!!"
else echo "Shame on you!"
fi
And I already tried writing "if" statement different ways, but outcome is always the same... I am obviously missing a point here, and I tried looking up simmilar simple problems on internet, and the ones I found work fine.. Don't see what mine is missing though..
Please help

Ner
 
Old 01-28-2004, 10:24 AM   #2
frandalla
Member
 
Registered: Oct 2003
Location: Tokyo - Japan
Distribution: Slackware
Posts: 348
Blog Entries: 1

Rep: Reputation: 37
right code:
#!/bin/bash
echo "Are you a good person?"
read ANSWER
if [ $ANSWER == "yes" ] ; then
echo "Good for you!!"
else echo "Shame on you!"
fi
 
Old 01-28-2004, 10:34 AM   #3
ner
Member
 
Registered: Oct 2003
Posts: 40

Original Poster
Rep: Reputation: 15
yeah, I tried that too, but it gives me

Line 4: [yes==yes]: command not found
Shame on you!!
 
Old 01-28-2004, 10:45 AM   #4
Demonbane
Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
the spaces inside the brackets matters
Code:
 if [ $ANSWER == "yes" ]
works, but not
Code:
 if [$ANSWER=="yes"]
 
Old 01-28-2004, 10:50 AM   #5
ner
Member
 
Registered: Oct 2003
Posts: 40

Original Poster
Rep: Reputation: 15
thank a lot Demonbane!
didn't think spaces would matter much.. but now it works!!
 
  


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
Simple shell script mikz Linux - General 1 02-24-2005 07:18 AM
simple shell script sharpie Programming 9 06-02-2004 11:47 PM
a simple shell script Warchief Programming 1 07-31-2003 05:01 AM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 10:14 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM


All times are GMT -5. The time now is 05:10 PM.

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