LinuxQuestions.org
Visit Jeremy's Blog.
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 10-08-2007, 08:13 PM   #1
sjcorp
LQ Newbie
 
Registered: Oct 2007
Posts: 8

Rep: Reputation: 0
Angry more help with if, else


I changed the -eq to "=", but I am still getting the same error:

--------------------------------------------------------------------------------

I am trying to do a simple file, but I cannot get it to work. Can you please let me know what I may be doing wrong. I am typing this using pico.

#!/bin/bash

echo -n "What is your last name?>"
read text
echo -n "Are you male or female?>"
read sex
if ($sex = "male"); then
echo "Hello Mr. $text"
else
echo "Hello Ms. $text"
fi

This is the output I receive:

What is your last name?>mmmmmmmm
Are you male or female?>male
./morf.test: line 7: male: command not found
Hello Ms. mmmmmmmm
 
Old 10-08-2007, 08:28 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I have not checked every line of code, but a test statement goes like this:

if [ $sex = "male" ]

Note that "[" is a synonym for "test", and that the space before and after is required
 
Old 10-08-2007, 08:37 PM   #3
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
#!/bin/bash

echo -n "What is your last name?>"
read text
echo -n "Are you male or female?>"
read sex
if [ $sex = "male" ]; then
echo "Hello Mr. $text"
else
echo "Hello Ms. $text"
fi

Exactly as pixellany said, in short.

Last edited by jay73; 10-08-2007 at 08:42 PM.
 
  


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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 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