LinuxQuestions.org
Help answer threads with 0 replies.
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, 09: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, 09:28 AM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,431

Rep: Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471Reputation: 2471
What language do you want to use? Bash, php, perl, C, other...?
What have you tried?
 
Old 05-09-2013, 09: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, 09: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, 09:37 AM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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, 09: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, 10:57 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
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, 11:23 AM   #8
bkirkham
LQ Newbie
 
Registered: May 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
thank you
 
Old 05-09-2013, 06:51 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
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 02: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 08:40 AM
Need a script to search and replace text in file using shell script unixlearner Programming 14 06-21-2007 10: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 08:15 PM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:48 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
Open Source Consulting | Domain Registration