Advertisement
Push28

menu test

Apr 3rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.82 KB | None | 0 0
  1. #!/bin/bash
  2. # utilitymenu.sh - A sample shell script to display menus on screen
  3. # Store menu options selected by the user
  4. INPUT=/tmp/menu.sh.$$
  5.  
  6. # Storage file for displaying cal and date command output
  7. OUTPUT=/tmp/output.sh.$$
  8.  
  9. # get text editor or fall back to vi_editor
  10. vi_editor=${EDITOR-vi}
  11.  
  12. # trap and delete temp files
  13. trap "rm $OUTPUT; rm $INPUT; exit" SIGHUP SIGINT SIGTERM
  14.  
  15. #
  16. # Purpose - display output using msgbox
  17. #  $1 -> set msgbox height
  18. #  $2 -> set msgbox width
  19. #  $3 -> set msgbox title
  20. #
  21. function display_output(){
  22.     local h=${1-10}         # box height default 10
  23.     local w=${2-41}         # box width default 41
  24.     local t=${3-Output}     # box title
  25.     dialog --backtitle "Linux Shell Script Tutorial" --title "${t}" --clear --msgbox "$(<$OUTPUT)" ${h} ${w}
  26. }
  27. #
  28. # Purpose - display current system date & time
  29. #
  30. function show_date(){
  31.     echo "Today is $(date) @ $(hostname -f)." >$OUTPUT
  32.     display_output 6 60 "Date and Time"
  33. }
  34. #
  35. # Purpose - display a calendar
  36. #
  37. function show_calendar(){
  38.     cal >$OUTPUT
  39.     display_output 13 25 "Calendar"
  40. }
  41. #
  42. # set infinite loop
  43. #
  44. while true
  45. do
  46.  
  47. ### display main menu ###
  48. dialog --clear  --help-button --backtitle "Linux Shell Script Tutorial" \
  49. --title "[ M A I N - M E N U ]" \
  50. --menu "You can use the UP/DOWN arrow keys, the first \n\
  51. letter of the choice as a hot key, or the \n\
  52. number keys 1-9 to choose an option.\n\
  53. Choose the TASK" 15 50 4 \
  54. Date/time "Displays date and time" \
  55. Calendar "Displays a calendar" \
  56. Editor "Start a text editor" \
  57. Exit "Exit to the shell" 2>"${INPUT}"
  58.  
  59. menuitem=$(<"${INPUT}")
  60.  
  61.  
  62. # make decsion
  63. case $menuitem in
  64.     Date/time) show_date;;
  65.     Calendar) show_calendar;;
  66.     Editor) $vi_editor;;
  67.     Exit) echo "Bye"; break;;
  68. esac
  69.  
  70. done
  71.  
  72. # if temp files found, delete em
  73. [ -f $OUTPUT ] && rm $OUTPUT
  74. [ -f $INPUT ] && rm $INPUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement