Im new to unix and shell scripting. I am required to write a program and im in the process of creating a menu system. I have my main menu but i want to be able to select an option that takes me onto another menu. I have tried doing this with the case statement with no luck so far. Wondering if it is possible or if there is another way i should be doing it?
This can get long and dull, but I often use this kind of thing for basic menu-type stuff:
clear
function main {
echo "Please choose:
1. Do Something
2. Do something else
3. Exit"
while true; do
read SELECT
case "$SELECT" in
1) SELECT=func_Something;;
2) SELECT=func_Something_else;;
3) SELECT=exit;;
*) echo Invalid selection.; continue
esac
break
done
}
function func_Something {
echo "In $0
Please choose:
1. Do Something More
2. Do something More else
3. Exit"
while true; do
read SELECT
case "$SELECT" in
1) SELECT=func_SomethingMore;;
2) SELECT=func_Something_More_else;;
3) SELECT=exit;;
*) echo Invalid selection.; continue
esac
break
done
}
function func_Something_else {
echo "in $0
Doing something else"
return 1
}
# ... write a function for each possible value of $SELECT...
main
while test $? -eq 0; do
$SELECT
done
print "1) sub menu"
print "2) nothing"
while true; do
read SELECT
case $SELECT in
1) print "a) option a"
print "b) option b"
while read SELECT2;do
case $SELECT2 in
"a") print "A selected";;
"b") print "B selected";;
esac
break 2
done;;
2) print "2 selected";;
esac
break
done
Output
poweredge:/home/brad/forum/scratch>menus
1) sub menu
2) nothing
1
a) option a
b) option b
b
B selected
poweredge:/home/brad/forum/scratch>menus
1) sub menu
2) nothing
1
a) option a
b) option b
a
A selected