![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Carreer:Networking Programming in Unix (C programming Language) | vibhory2j | UNIX for Dummies Questions & Answers | 5 | 09-05-2008 04:57 PM |
| UNIX newbie NEWBIE question! | Hanamachi | UNIX for Dummies Questions & Answers | 3 | 09-14-2006 07:23 AM |
| c programming or unix programming!? | moxxx68 | High Level Programming | 1 | 03-30-2004 05:53 AM |
| programming question from a newbie, please help | milenky | High Level Programming | 1 | 10-11-2002 07:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
OK, so I'm trying to finish my last individual assignment for this course, and it's the first time I've visited a forum (I've actually understood UNIX up to this point). I am having trouble with this one. I have to write a program that prompts the user to type their first name and stores it in a variable, then prompts for their last name and stores it as well, and then displays "You entered LastName, FirstName. Is that correct?" and if the user enters y or yes, it replies "Thank You!" or if the user enters n or no, the script restarts, prompting for the user's first name again. Here's what I have so far:
#!/bin/bash while [ $confirm != "y"] do echo Please enter your first name: read fname echo Please enter your last name: read lname echo You entered $lname, $fname. Is that correct? read confirm done echo Thank You! So far, I am getting an error message in the second line, referencing the first "[" symbol. Not sure why. I also don't know how to test for y and yes, right now it only tests for the y character. I need to also test for yes. Please help! It's probably something really stupid, but I'm just new to this! Thank you so much for any hints or anything at all. Have a good night. MetalGoddess |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
The rules say
(6) Do not post classroom or homework problems. But since you have done most of the work, I will point out a syntax error that you have. Code:
while [ $confirm != "y"] Code:
while [ $confirm != "y" ] |
|
#3
|
|||
|
|||
|
Just link the second condition with -o as
while [ $confirm != "y" -o $confirm != "yes" ] .... |
|
#4
|
||||
|
||||
|
I noticed you said you are a programming "newbie" in UNIX. So I think I need to say the following.
The '[' used to be the same as the program "test". It is now a shell builtin, with basically the same function. The '[' character is also recognized by the shells (sh|ksh|bash) as a 'special character', and as such, requires you to 'finish' the syntax with the ']' character. The way to do this is to have the ']' stand-alone, separate (by whitespace) from other characters (or with a 'defined' termination character, like --> '];' ). THAT is why you got the error you were getting. The shell could not find a terminating ']' character. The '[' is "test", but also an "open bracket". It needed to find a "close bracket" to complete the syntax. B.T.W.: the tests for 'y', 'Y', 'yes', 'Yes', or 'YES' could more easily be accomplished with a 'case' statement. Easier to understand, and easier to adjust in the future, too. |
||||
| Google The UNIX and Linux Forums |