Shell scripting/menu

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Shell scripting/menu
# 8  
Old 05-05-2013
What type of system are you using? (The treatment of backslash characters in echo arguments varies from system to system. And the way you're using echo seems strange for any operating system.) Have you considered using printf instead of echo?

Can you explain the difference between strings delimited by double quotes ("...") and by single quotes ('...')? Are all of you quotes matched? And, yes, just use plain double quotes ("); not opening double quotes and closing double quotes (and )!

What shell are you using? Look at your shell's man page for the format of a case statement and the format of a while statement? I don't know of any shell that accepts a compound statement of the form:
Code:
case "$choice" in
while true
do
 ... ... ...
done
*)	echo "Invalid option"   # ;; not needed for last option
esac

You don't want to put some cases in a loop; you want to put the case statement in a loop. You also need to decide if you want the menu to only appear once, or to appear every time through the loop.
# 9  
Old 05-05-2013
Quote:
I think I just have to move done above choice 5?
Basically yes. Here's one good approach. Get something simple working. Make a simple loop, like Corona688 showed before, and put one thing in it. For example, ask the user for their choice, print their choice, and if the choice is 5, exit. Once that is working, put in something else. At each step, keep the code working. It's the best way to develop. That way you deal with one problem at a time.

Yes, just use simple "double quotes". Are you using Word or something like that? You have to use a text editor for it to work.
# 10  
Old 05-06-2013
I stripped it down to this:

Code:
# Use of a case statement to offer a 5 item menu
echo "  Menu\n
1. Copy a file to a designated directory\n
5. Quit to Unix\nEnter your option #: \c"
 
read choice
 
case "$choice" in
while true
do
1)      echo " Chose a file to be copied to your /etc directory;;
       read filename;;
       cp $filename /etc;;
done
5)      exit ;;
*)      echo "Invalid option"   # ;; not needed for last option
esac

but I am getting ./example: 8: Syntax error: word unexpected (expecting ")")

any ideas?
# 11  
Old 05-06-2013
Quote:
Originally Posted by Jagst3r21
I stripped it down to this:

Code:
# Use of a case statement to offer a 5 item menu
echo "  Menu\n
1. Copy a file to a designated directory\n
5. Quit to Unix\nEnter your option #: \c"
 
read choice
 
case "$choice" in
while true
do
1)      echo " Chose a file to be copied to your /etc directory;;
       read filename;;
       cp $filename /etc;;
done
5)      exit ;;
*)      echo "Invalid option"   # ;; not needed for last option
esac

but I am getting ./example: 8: Syntax error: word unexpected (expecting ")")

any ideas?
I suggested some ideas in message #8 in this thread. It doesn't look like you considered anything I posted there, and the problems you're showing here seem to be the same as the problems you had then.

Is this really an exact copy of the script you ran when you got the error message above? I would have expected it to complain about line 9 instead of line 8 with the code you listed above.
# 12  
Old 05-06-2013
Quote:
any ideas?
Go back to post number two, and look at the while loop. Everything has to fit inside the while loop. Put one echo and one read inside the while loop for starters. Once that is working, put your case statement inside the while loop too, to deal with the user response.
# 13  
Old 05-07-2013
Jagst3r21
Your approach presents your menu to the user only once and if he has not selected to exit then it goes on to loop infinitely.
The proper approach should be to loop the menu too so that once you have served the users request for the first time you again go back to the user to get his input and ask him whether he wants to quit if yes then get out of the loop
And also you dont need to have ;; in every line within case statement .Search for some case examples I am sure you will come to know what is going wrong in your script
# 14  
Old 05-14-2013
My Try

This is what i found

Code:
# Use of a case statement to offer a 5 item men
echo "Menu
1. Copy a file to a designated directory
2. Check whether a specified user is logged in
3. Display the details of a specified file
4. List the contents of a specified directory
5. Quit to Unix "

while :
do
echo "Enter your option "
read choice
case $choice in
1)	echo "Chose a file to be copied to your /etc directory:
        read filename
        cp $filename /etc;;
2)	echo "Enter the name of a user to check if they are logged in"
        read name
        who | grep $name;;
3)      echo "Enter the name of a file to check it's details"
        read name
        ls -l $name;;
4)      echo "Enter the name of a directory to list its contents"
        read name
        ls $name;;
5)      exit ;;
*)	echo "Invalid option "   # ;; not needed for last option
esac
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Menu and case statement scripting

hi all i am trying to get help with writing a script using case statement to display menu as 1) Authentication log 2) System log 3) Messages 4) Dmesg 5) Boot log Q) Exit When selecting the menu by 1 or 2 or 3 o 4 or 5, it should display the last 10 lines of the log files, if... (3 Replies)
Discussion started by: renegade11
3 Replies

2. Shell Programming and Scripting

Menu shell script help

Hi All, I have written a shell script that show menu driven option. My requirement is that in the menu driven option i want to select multiple choice. i.e if i want to select 1 or 1,2 or 1,2,3 or 2,3 etc .... Can some one help me in that My script. while true; do echo " " ... (8 Replies)
Discussion started by: Nawrajesh
8 Replies

3. Shell Programming and Scripting

Menu using shell script

Hi, I need to have a shell script for the below need. 1. Menu with one heading and 4 options. 2. the heading and 4 options are taken from a file. File entry ====== Heading1|option1|option2|option3|option4| Heading2|option1|option2|option3|option4| 3. the user entries must be captured in... (9 Replies)
Discussion started by: umastinu
9 Replies

4. Shell Programming and Scripting

Shell script menu

hi guys, how would you do the following? I have a menu with 5 options in my shell script: 1. Run function 1 against files 2. Run function 2 against files 3. Run function 3 against files 4. Run function 4 against files 5. Run function 5 against files I'd like to be able to run multiple... (10 Replies)
Discussion started by: rich@ardz
10 Replies

5. UNIX for Dummies Questions & Answers

Scripting menu problem

Hi there, I am new to Unix and at the moment I am trying to solve my assignment that is to create a script for the program to prompt user to type three codes, from user point of view it should be done by typing codes separating them by spaces. Then program displays a menu with these three... (5 Replies)
Discussion started by: Dannel
5 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

help with scripting a simple menu

Hi there. I'm trying to teach myself UNIX but the book I bought is a bit confusing. I'm trying out this exercise and I think I'm on the right track, but I'd appreciate any suggestions on how to improve what I have so far. Also, I'm not clear on how to use the read command to utilize the user's... (3 Replies)
Discussion started by: Jsmith
3 Replies

8. Shell Programming and Scripting

Scripting problem - when the file is not found i want it to return to the menu

when the file is not found i want it to return to the menu, however it carries out the next line when i hit a key I know its probably something simple can anyone help? here is my pause function: function pause(){ read -s -n 1 -p "Press any key to return to Menu . . ." echo } SCRIPT... (2 Replies)
Discussion started by: Alendrin
2 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

10. Shell Programming and Scripting

scripting for menu

Hi, I'm writting a script to filter a cvs log and get only the modified files to move them to a specific directory to compile. I try to filter a line and move from source to target, with no results. Could you help me? for example, in the cvs log file appears: cat log.txt U... (2 Replies)
Discussion started by: Manu
2 Replies
Login or Register to Ask a Question