Results 1 to 3 of 3
This code is then ran give me an error saying there is something wrong with the syntax at the "done"
begin code
#! /bin/bash
#start a loop
while [ choice ...
- 04-14-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 3
Help on Simple Menu Script (PLEASE HELP!!!)
This code is then ran give me an error saying there is something wrong with the syntax at the "done"
begin code
#! /bin/bash
#start a loop
while [ choice != "0" ]
do
clear
#display menu
echo "UNIX Helper Utility
l -- list file names in current directory
o -- sign on this session
f -- sign off this session
d -- display the time and date
b -- background job
s -- interactive shell
q -- quit"
#get variable
read choice
#if else statements for your choices
if [ "$choice" = "l" ]
#list files
then ls
else if [ "$choice" = "o" ]
#sign on
then signon
else if [ "$choice" = "f" ]
#sign off
then signoff
else if [ "$choice" = "d" ]
#display date
then date
else if [ "$choice" = "b" ]
#run background job
then sleep 500 &
else if [ "$choice" = "s" ]
#run interactive shell
then good
else [ "$choice" = "q" ]
#quit
exit
fi
#display menu again
echo "press RETURN for menu"
read key
done
exit 0
end code
- 04-14-2010 #2
Hi, your usage of the 'else if' statement is causing this. In bash, you use elif. If you adjust it, it'll run.
A tip on style, for this sort of menus a case statement may be more readable.
Code:case $choice in option1) command1 ;; option2) command2 ;; option3) command3 ;; option4|option5|option6) # more than one option is possible command456 ;; *) # all the rest command-x ;; esacCan't tell an OS by it's GUI
- 04-14-2010 #3Just Joined!
- Join Date
- Mar 2010
- Posts
- 3
ok now I need to be able to return to the beginning of the script and redisplay the menu until the user chooses "q" for quit. What I have isnt working.


Reply With Quote