LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2013, 10:21 AM   #1
bkirkham
LQ Newbie
 
Registered: May 2013
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 05-09-2013, 10:28 AM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,989

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
What language do you want to use? Bash, php, perl, C, other...?
What have you tried?
 
Old 05-09-2013, 10:30 AM   #3
bkirkham
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
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 ')"
 
Old 05-09-2013, 10:32 AM   #4
bkirkham
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
or I get syntax error unexpected end of file
 
Old 05-09-2013, 10:37 AM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 7,679
Blog Entries: 10

Rep: Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080Reputation: 2080
Quote:
Originally Posted by bkirkham View Post
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?
 
Old 05-09-2013, 10:47 AM   #6
bkirkham
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-09-2013, 11:57 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
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.
 
Old 05-09-2013, 12:23 PM   #8
bkirkham
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
thank you
 
Old 05-09-2013, 07:51 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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 )
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to get name of file, delete original file, rename blank file chrisgti Linux - General 11 09-15-2012 03:49 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 11:37 PM
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 09:15 PM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 12:00 PM


All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration