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.
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.