I am writing a bash script. It is menu driven.
For some reason, i use a case statement, and after all my options are printed, i use the * to capture anything else the user may type. but for some reason, my output is not being done.
Example:
while [ 1 ]; do
if [ $MAIN_MENU -eq 1 ]; then
printMainMenu
read option
case "$option" in
"1" ) printDiskSpace;;
"2" ) printFreeMemory;;
"0" ) exit;;
"*" ) echo "Input not understood.";;
esac
fi
done
Now what happens is when I use the menu, if i type 1, 2, or 0 it does the proper thing. but if i typed 55 for instance, it would just redisplay the menu without echoing "input not understood".
Am i missing something here?
Thanks!
Use *) not "*") for Bash default cases.
So, in your example:
*) echo "Input not understood.";;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With