LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script file (https://www.linuxquestions.org/questions/linux-newbie-8/script-file-4175461282/)

bkirkham 05-09-2013 09:21 AM

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.

yancek 05-09-2013 09:28 AM

What language do you want to use? Bash, php, perl, C, other...?
What have you tried?

bkirkham 05-09-2013 09:30 AM

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 ')"

bkirkham 05-09-2013 09:32 AM

or I get syntax error unexpected end of file

Habitual 05-09-2013 09:37 AM

Quote:

Originally Posted by bkirkham (Post 4947901)
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 ')"

Post the code?

bkirkham 05-09-2013 09:47 AM

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

grail 05-09-2013 10:57 AM

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.

bkirkham 05-09-2013 11:23 AM

thank you

chrism01 05-09-2013 06:51 PM

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.