Advertisement
Guest User

nikitogx

a guest
Jun 24th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.78 KB | None | 0 0
  1. #!/bin/bash
  2. # A menu driven shell script sample template
  3. ## ----------------------------------
  4. # Step #1: Define variables
  5. # ----------------------------------
  6. EDITOR=vim
  7. PASSWD=/etc/passwd
  8. RED='\033[0;41;30m'
  9. STD='\033[0;0;39m'
  10.  
  11. # ----------------------------------
  12. # Step #2: User defined function
  13. # ----------------------------------
  14. pause(){
  15.   read -p "Press [Enter] key to continue..." fackEnterKey
  16. }
  17.  
  18. one(){
  19.     echo "one() called"
  20.         pause
  21. }
  22.  
  23. # do something in two()
  24. two(){
  25.     echo "two() called"
  26.         pause
  27. }
  28.  
  29. # function to display menus
  30. show_menus() {
  31.     clear
  32.     echo "~~~~~~~~~~~~~~~~~~~~~"   
  33.     echo " M A I N - M E N U"
  34.     echo "~~~~~~~~~~~~~~~~~~~~~"
  35.     echo "1. Get user data "
  36.     echo "2. Copy everything in a directory "
  37.     echo "3. "
  38.     echo "4. Create new account"
  39.     echo "5. Change ownership of all files of previous owner"
  40.     echo "6. Block account"
  41.     echo "7. Check for proccesses of an account"
  42.     echo "8. Check if there are active processes and stop them"
  43.     echo " "
  44.     echo "0. Exit"
  45. }
  46. # read input from the keyboard and take a action
  47. # invoke the one() when the user select 1 from the menu option.
  48. # invoke the two() when the user select 2 from the menu option.
  49. # Exit when user the user select 3 form the menu option.
  50. read_options(){
  51.     local choice
  52.     read -p "Enter choice [ 1 - 3] " choice
  53.     case $choice in
  54.         1) one ;;
  55.         2) two ;;
  56.         3) exit 0;;
  57.         *) echo -e "${RED}Error...${STD}" && sleep 2
  58.     esac
  59. }
  60.  
  61. # ----------------------------------------------
  62. # Step #3: Trap CTRL+C, CTRL+Z and quit singles
  63. # ----------------------------------------------
  64. trap '' SIGINT SIGQUIT SIGTSTP
  65.  
  66. # -----------------------------------
  67. # Step #4: Main logic - infinite loop
  68. # ------------------------------------
  69. while true
  70. do
  71.  
  72.     show_menus
  73.     read_options
  74. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement