Advertisement
Guest User

Script Template For Devs to Bash And Shell Scripts

a guest
Apr 26th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.67 KB | None | 0 0
  1. #!/bin/bash
  2. # Sample Script Template for Bash and Shell Script
  3.  
  4. trap finish 0
  5. trap cleanup 1 2 3 6
  6.  
  7. function checksudocommand()
  8. {
  9.     if [ $(id -u) -ne 0 ];
  10.     then
  11.         echo -e "\nYou must run this script as root. You are able to use the sudo command.\n"
  12.         exit 1
  13.     fi
  14. }
  15.  
  16. function cleanup()
  17. {
  18.     echo "Caught Signal ... cleaning up."
  19.     echo "Done cleanup ... quitting."
  20.     exit 1
  21. }
  22.  
  23. function finish()
  24. {
  25.     # comment with code
  26.     # script
  27.     exit 0
  28. }
  29.  
  30. function main()
  31. {
  32.     echo -e "\nHello, World!\n"
  33. }
  34.  
  35. function usage()
  36. {
  37.     grep '^#/' "$0" | cut -c4-
  38.     exit 0
  39. }
  40.  
  41. expr "$*" : ".*--help" > /dev/null && usage
  42.  
  43. #### Main Program ####
  44. checksudocommand
  45. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement