Outra maneira é evitar selecionar e criar um menu. Faça um script de shell para cada opção de menu (action1.sh, xxx.sh e passwords.sh), configurá-los no menu.cfg:
1 action1 Do action 1
2 xxx Another nice item for you
3 passwords Very dangerous
E inicie um menu com um script que leia menu.cfg
#!/bin/ksh
formatmenu()
{
if [ $# -eq 2 ]
then
printf "%d) %s\n" ${1} "$2"
else
printf " %s\n" "${1}"
fi
}
showMenu()
{
echo "Enter 0 to stop or choose beneath."
cat menu.cfg|while read option proces description
do
formatmenu ${option} ${proces}
formatmenu "${description}"
done
}
getAction()
{
showMenu
while [ ${CHOICE} -eq -1 ]
do
read CHOICE?"Please enter a digit: "
if [[ ${CHOICE} != +([0-9]) ]]
then
CHOICE=-1
echo "Invalid, please enter a digit."
fi
done
}
performAction()
{
if [ ${CHOICE} -eq 0 ]
then
return
fi
process=$(grep "^${CHOICE} " menu.cfg | cut -d\ -f2)
echo "===${process}.sh==="
. ${process}.sh
}
# Start
export CHOICE=-1
getAction
echo choice=${CHOICE}
performAction
exit 0