Fajar Priyanto wrote:
> Dear All,
> Can we make menu in bash script just like in DOS' batch file?
> Such as:
> =======
> [Menu]
> Pls select what you want to do:
> 1. Copy /etc/dhcpd.conf
> 2. Copy /etc/wvdial.conf
> 3. Make directory /var/log/nullmailer
> 4. Do all of above
> ======
> Could you please give me some examples?
> Thanks

It's very easy with "case" operator.

Here is the source (is is also attached - just save it, "chmod +x menu.sh" and 
launch it "./menu.sh"):

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash

#output a menu

echo "[menu]"
echo "1 do this"
echo "2 do that"
echo "3 etc"

#echo with no end-of-line
echo -n "selection: "

#read user input
read action

#do something depending on input stored in $action variable
case $action in
1) echo "you selected 1"
#put action 1 here
;;
2) echo "you selected 2"
#put action 2 here
;;
3) echo "you selected 3"
#put action 3 here
;;
*) echo "you can select only 1, 2 or 3" #default action
;;
esac

#that's all
echo "bye"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hope this helps.

Artemio.

Attachment: menu.sh
Description: application/shellscript

Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to