shell script menu


/ Published in: Bash
Save to your folder(s)

menu will only quit when 'q' is pressed


Copy this code and paste it in your HTML
  1. #!/bin/sh
  2. echo "Use one of the following options"
  3. echo " d : run date command"
  4. echo " <?> : <another thing to do ...>"
  5. echo " q: quit this menu"
  6. echo "enter your choice or type "q" to quit : \c"
  7. read option
  8. while [ "$option" != "q" ]
  9. do
  10. case $option in
  11. d ) date
  12. shift
  13. echo "enter your choice or type "q" to quit : \c"
  14. read option
  15. ;;
  16. <?> ) <another command...>
  17. shift
  18. echo "enter your choice or type "q" to quit : \c"
  19. read option
  20. ;;
  21.  
  22. # ...
  23.  
  24.  
  25. * )
  26. echo "invalid choice!"
  27. shift
  28. echo "enter your choice or type "q" to quit : \c"
  29. read option
  30. ;;
  31. q ) exit 0
  32. ;;
  33. esac
  34. done
  35. exit 0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.