#!/bin/bash
IFS="|"
set -- main
while [ "$#" -gt 0 ]
do
case "$1" in # Look up the right options for the menu
main) OPTIONS="Do maintenance|Look at logs|Look at Processes|Q" ;;
submenu1) OPTIONS="A|B|C|Q" ;;
submenu2) OPTIONS="D|E|F|Q" ;;
submenu3) OPTIONS="X|Y|Z|Q" ;;
esac
PS3=$'\n'"$1 menu: " # Special variable controlling select prompt
# Print menu, get reply
select X in $OPTIONS
do
[ -z "$X" ] || break
done
# We treat Q specially, it returns to the previous menu.
if [ "$X" = "Q" ]
then
shift # Return to previous menu
continue # Go to top of loop
fi
case "$1" in
main)
case "$X" in
Do maintenance) set -- submenu1 "$*" ;;
Look at logs) set -- submenu2 "$*" ;;
Look at Processes) set -- submenu3 "$*" ;;
esac
;;
submenu1)
case "$X" in
A) # Switch to submenu2 by removing submenu1 before adding
shift
set -- submenu2 "$*"
;;
B) ;;
C) ;;
esac
;;
submenu2)
case "$X" in
A) ;;
B) ;;
C) ;;
esac
;;
submenu3)
case "$X" in
A) ;;
B) ;;
C) ;;
esac
;;
*) echo "Unknown menu $1, removing"
shift
;;
esac
done
echo "Menu list is empty, quitting" >&2
I tried the exact code that you posted and it works a charm. But if i modify it as highlighted above, then i am getting the following error.
Quote:
./menu.sh: line 58: syntax error near unexpected token `OF'
./menu.sh: line 58: ` Do maintenance) set -- submenu1 "$*" ;;'
In addition, if i define the menus your way, they aren't aesthetically goodlooking which is a requirement for the script. I designed the menu function using tput so that the menus will be properly spaced and will be in the centre of the terminal. I tried calling the tput function to align the menu using backticks as below and it got messy to say the least
Code:
i=1
j=4
main) OPTIONS="`align $i $j`;Do maintenance|`align $i $j`;`align $i $j`;Look at logs|`align $i $j`;Look at Processes|Q" ;;
# The align function has a bunch of tput commands and increments the value of i and j for each call of the function.
I am attempting to create a shell script with the following capaciblities:
1. Listed options to choice from
2. Use to perform awk statements
3. Print a report with the awk results
My questions are
1. How do I select more than one file for option #5 and #6
2. How to I create an... (11 Replies)
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... (2 Replies)
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)
Im new to unix/linux and am having trouble with this one.
My problem is when i enter 9 to exit it doesnt do so.
also option 6 doesent display the time. Its getting to be frustrating.
I know there are probably alot of bug in this bu these basic ones are really odd.
#!bin/bash
#
until ... (3 Replies)
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)
HI All..
below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file.
problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
I'm writing a shell script and have a problem with selection when I issue the command, is there a way to automatically choose a selection number one after a selection menue appear
Command
1-choice
2- choice
3-choice
Thanks
Sara (3 Replies)
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)
I have a menu option which will look as follows
Select a menu option
1.change password
2.login as root user
3.show system version
4.quit
Select> 1
please enter the new password: unix
reenter the new password: unix
press any key to enter
(then displays again the menu options to enter the... (4 Replies)
Hi Friends,
I have a menu based tool which requires input/option to proceed further. How to make a shell script ?
eg: menu looks like
Get_data.sh
to continue (y/n) :
Here I need to key in "y" to proceed.
I want to prepare a script which should consider option y. (5 Replies)