LinuxQuestions.org
Review your favorite Linux distribution.
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 04-06-2009, 05:19 PM   #1
acidblue
Member
 
Registered: Apr 2003
Posts: 152

Rep: Reputation: 15
User input keeps kicking error: Yes command not found


I'm trying to compare two strings in an If..then statement and am having an awful time trying to get to work.
The user has to enter either yes or no to a question, but i keep getting "yes: command not found"
here is a sample:

echo 'Is this for GH 3 part? yes/no'
read GH_answer
echo $GH_answer

if ["$GH_answer" = "yes"];then
GH_result = $(($target_ppm - $current_ppm / $target_ppm) * 8 * $res_gallons)
Micro = $GH_result * 2
echo 'GH Bloom is $GH_result'
echo 'Micro is $Micro'
else

echo 'Is this for Flora Nova 2 part? yes/no'
read FN_answer
if ["$FN_answer" = "yes"];then
FN_result=$(($target_ppm - $current_ppm) / $target_ppm * 8 * $res_gallons)
echo "Then add $FN_result ml of Flora Nova Bloom"
else
echo 'Please restart, it must be one or the other.'

fi
fi


I've tried this several different ways and keep getting the same error, when ever the user inputs yes or no.
I'm a bit new to bash scripting, so any help would be greatly appreciated.
 
Old 04-06-2009, 05:26 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
I ran your script in with a trace on to reproduce the problem. Here's what I saw:
Code:
$ sh -x hmm.sh 
+ echo 'Is this for GH 3 part? yes/no'
Is this for GH 3 part? yes/no
+ read GH_answer
yes
+ echo yes
yes
+ '[yes' = 'yes]'
hmm.sh: line 7: [yes: command not found
Line 7 (after I added a sh-bang line) is:
Code:
if ["$GH_answer" = "yes"] ; then
I correct that by using white space, like so:
Code:
if [ "$GH_answer" == "yes" ] ; then
You'll need to do the same in a couple other places in your script as well.
 
Old 04-06-2009, 05:54 PM   #3
acidblue
Member
 
Registered: Apr 2003
Posts: 152

Original Poster
Rep: Reputation: 15
Oh yes the double ==. and white space i never would of thought of that, thanks.
Now i'm getting an error on my math: syntax error near unexpected token '/'.
'/' is for division?
 
Old 04-06-2009, 08:56 PM   #4
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Always back to Fedora
Posts: 267

Rep: Reputation: 54
Quote:
Originally Posted by acidblue View Post
Oh yes the double ==. and white space i never would of thought of that, thanks.
Now i'm getting an error on my math: syntax error near unexpected token '/'.
'/' is for division?
You can use the function "expr" to evaluate expressions in your script. The forward slash does not imply division in a script unless you use it it in something like expr ARG1 / ARG2
 
  


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
cp command failing for large files - Input/Output error googs Linux - General 5 08-09-2012 12:28 PM
Unable to compile C++ programs.make:g++ command not found error.Error 127 PrathuD Programming 3 03-16-2009 12:44 PM
User input into Bash scripts and checking validity of user input?? helptonewbie Programming 8 07-07-2008 06:40 PM
command not found error Deelk Slackware 12 04-23-2006 02:12 PM
Adding user creating command not found problem Geetha S R SUSE / openSUSE 3 01-17-2006 07:20 AM


All times are GMT -5. The time now is 01:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration