
sh newb: case menus w/scripts
Building case menus and including entire scripts in case options.
Suppose you wanted to write a script where you gave the user the option
of choosing between two seperate scripts to run (that were too small to merit
a seperate file).
The first script alone, could read:
----------------------------------------
#!/bin/sh
## echo script
echo kkkkkkkkkkkk
echo kkkkkkkkkkkk
echo jjjjjjjjjjjj
---------------------------
and the second could look like:
-------------------------------------
#!/bin/sh
## head script
for file in `ls`
do head -2 $file
done
-----------------------------
The basic template is simple:
"option" )\
......................; \
......................; \
......................; \
;;
with the "..............." representing each line in the script you
want to include.
When putting them in a case script, you need a ";" wherever a newline
would be, and a "\" wherever a literal line ends in the case rendition.
--------------------------------------------------------------------------
#!/bin/sh
clear
# clears the screen first
echo
echo
echo
echo "[a] Choose this execute echo script"
echo
echo "[b] Choose this to execute head script "
echo
echo
echo
# the above part displays the choices on the screen with the lone "echo"s
# giving blank lines for formatting purposes.
read mm # offers a prompt and takes input
# could be "abc" or "snort" instead of "mm"
# there must be no spaces after the "\" below
case "$mm" in
"a" )\
echo kkkkkkkkkkkkk ; \
echo kkkkkkkkhhhhh ; \
echo jjjjjjjjjjjjj ; \
;;
"b" )\
for file in `ls` ; \
do head -2 $file ; \
done ; \
;;
*) echo "Not a valid option. Exiting." ; exit 1 \
;;
esac
exit 0
---------------------------------------------------------------------
# the *) just means "any other choices"
Alan C
--
take control of your mailbox ----- elrav1 ----- http://www.**-**.com/