Posted By

rwczippy on 08/16/08


Tagged

menu Shell Bash script case while


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

jamesming
sherz
srinivasga
vthreex


shell script menu


 / Published in: Bash
 

menu will only quit when 'q' is pressed

  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
Posted By: jaduks on December 21, 2008

Nice one. I have one more menu done in cat.

http://unstableme.blogspot.com/2008/06/bash-script-menu.html

You need to login to post a comment.