Results 1 to 4 of 4
Hello, I have a question regarding a bash script.
Code:
#ask for first name and assign to firstName
echo -e "\nWhat is your First name? "
read firstName
I would ...
- 03-30-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 3
N00B Bash script question
Hello, I have a question regarding a bash script.
I would like to add and if statement like thisCode:#ask for first name and assign to firstName echo -e "\nWhat is your First name? " read firstName
My question is how do I come out of the if statement and back to the "what is your name?"Code:if [firstName == ""] then echo -e "\nPlease enter a name."
Sorry if this is unclear or if the syntax isn't correct. I only have a small amount of coding knowledge and its Java...
Thanks in advance!!
- 03-30-2009 #2Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
You might want to use a while loop:
Code:firstname="" while [ "$firstname" == "" ]; do echo -ne "\nWhat is your First name? " read firstname if [ "$firstname" == "" ]; then echo "Please enter name." fi doneRHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.
- 03-30-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 3
- 03-30-2009 #4Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
Absolutly, and of course as with most programming there are lots of ways to get things done....
RHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.


Reply With Quote
