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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-08-2007, 08:13 PM
|
#1
|
LQ Newbie
Registered: Oct 2007
Posts: 8
Rep:
|
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
|
|
|
10-08-2007, 08:28 PM
|
#2
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
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
|
|
|
10-08-2007, 08:37 PM
|
#3
|
LQ Guru
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019
Rep: 
|
#!/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.
|
|
|
All times are GMT -5. The time now is 07:48 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|