LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Simple shell script is driving me crazy (http://www.linuxquestions.org/questions/linux-newbie-8/simple-shell-script-is-driving-me-crazy-139607/)

ner 01-28-2004 10:19 AM

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

frandalla 01-28-2004 10:24 AM

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

ner 01-28-2004 10:34 AM

yeah, I tried that too, but it gives me

Line 4: [yes==yes]: command not found
Shame on you!!

Demonbane 01-28-2004 10:45 AM

the spaces inside the brackets matters
Code:

if [ $ANSWER == "yes" ]
works, but not
Code:

if [$ANSWER=="yes"]

ner 01-28-2004 10:50 AM

thank a lot Demonbane! :)
didn't think spaces would matter much.. but now it works!! :)


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