Skip to content

Instantly share code, notes, and snippets.

@ccraig
Created June 17, 2014 17:14
Show Gist options
  • Save ccraig/f208fe38cb2c35d7a597 to your computer and use it in GitHub Desktop.
Save ccraig/f208fe38cb2c35d7a597 to your computer and use it in GitHub Desktop.
Example of a basic menu driven program in bash
#!/bin/bash
function p
{
echo $@
}
function displayMenu
{
p ""
p "1) Start"
p "2) Stop"
p "3) Quit"
p ""
p -n "Enter selection: "
}
function startProg
{
p "Starting..."
}
function stopProg
{
p "Stopping..."
}
function quitProg
{
p "Bye, bye"
exit 0
}
function processInput
{
case "$1" in
1) startProg ;;
2) stopProg ;;
3) quitProg ;;
*) ;;
esac
}
#Main
while [ 0 -lt 1 ]; do
displayMenu
read input
processInput $input
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment