Advertisement
xzlui

Linux Shell Script Example

Dec 18th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. #!/bin/bash
  2. #For beginners who want a better understanding of shell scripting on Linux systems
  3. #Coded on Ubuntu 16.04+
  4. #Execute script in terminal: bash /path/to/script.sh or ./path/to/script.sh
  5. clear
  6.  
  7. # INITIALIZATION
  8. echo -e '\033]2;Terminal\007'
  9.  
  10. KEY=$RANDOM
  11.  
  12. until [[ $sac == $KEY ]] ; do
  13. clear
  14. read -p "Session Access Key: " sac
  15. if [[ $sac == "/grant" ]] ; then
  16.     echo
  17.     echo $KEY
  18.     sleep 2
  19. elif [[ $sac == $KEY ]] ; then
  20.     echo
  21.     echo Access granted!
  22.     sleep 1
  23. else
  24.     echo
  25.     echo Access Denied!
  26.     exit 0
  27. fi
  28. done
  29.  
  30. # FUNCTIONS
  31. doFunc1() {
  32.     echo "This is the first function."
  33.     sleep 1
  34. }
  35.  
  36. doFunc2() {
  37.     echo "This is the second function."
  38.     sleep 1
  39. }
  40.  
  41. doFunc3() {
  42.     echo "This is the third function."
  43.     sleep 1
  44. }
  45.  
  46. # MAIN LOOP
  47. while true ; do
  48. clear
  49. echo "1) doFunc1"
  50. echo "2) doFunc2"
  51. echo "3) doFunc3"
  52. echo
  53. read -p '$ ' opt
  54. case "$opt" in
  55.     "1")
  56.         doFunc1 ;;
  57.     "2")
  58.         doFunc2 ;;
  59.     "3")
  60.         doFunc3 ;;
  61.     *)
  62.         echo "This is not a function."
  63.         sleep 1 ;;
  64. esac
  65. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement