script file
I need to write a script file that will let my users make choices a,b,c. I need some help with the syntax.
|
What language do you want to use? Bash, php, perl, C, other...?
What have you tried? |
I'm using bash, I have finally got the script to run but it keeps giving me a syntax error, saying syntax error near unexpected token ')"
|
or I get syntax error unexpected end of file
|
Quote:
|
echo -e "what would you like to see?
The contents of the /bin (a) mv choices.txt to choices2.txt (b) top (c) Enter your choice (a/b/c)-->\c" read ANSWER if [ $Answer = "a" -o $Answer = "A" ] then echo -e "\nThe contents of the /bin are: \c" elif [ $Answer = "b" -o $Answer = "B" ] then echo -e mv choices.txt to choices2.txt elif [ $Answer = "c" -o $Answer = "C" ] then echo -e top *echo -e "Invalid Choice!\a" fi |
So first off, please use [code][/code] tags around your code to make it more readable.
As for the code: 1. Use -n instead of escape c (\c) as it makes the code a little cleaner 2. Variable ANSWER is NOT the same as variable Answer (bash is case sensitive in this regard) 3. Without the code tags it is hard to tell, but be aware that [ is a command and hence you need a space before and after it 4. As you are using bash I would promote using [[ over [ - see here for more information 5. For debugging purposes, use set -xv as the second line in your script and try executing to see where the error lies. The above should give you a little bit to think about. |
thank you
|
I'd like to expand on grail's num 2: in fact Linux, Unix are case sensitive for everything, not just for this particular usage :)
(This is for OP: grail already knows ;) ) |
All times are GMT -5. The time now is 10:13 PM. |