Posted By

mattdanielbrown on 05/04/19


Tagged

bashshtemplatescriptstarter


Versions (?)

Bash Script Template


 / Published in: Bash
 

Basic Bash Shell Script Template, includes USAGE function, simple argument parsing, and a MAIN function.

  1. #!/usr/bin/env bash
  2. #
  3. # filepath.sh
  4. # Script description
  5. # v0.0.1
  6. # 01-01-2020
  7.  
  8. #-----------------------------------------------------------------------------#
  9. # VARIABLES
  10. #-----------------------------------------------------------------------------#
  11. PROGRAM_NAME="$0"
  12. #VAR_ONE="abc"
  13. #VAR_TWO=123
  14. #VAR_THREE=true
  15.  
  16. #-----------------------------------------------------------------------------#
  17. # FUNCTIONS
  18. #-----------------------------------------------------------------------------#
  19. function one() {
  20.  
  21. }
  22.  
  23. function two() {
  24.  
  25. }
  26.  
  27. function parse_arguments() {
  28. while getopts “:a:bc” opt; do
  29. case $opt in
  30. # a) AOPT=$OPTARG ;;
  31. a)
  32. one
  33. ;;
  34. b)
  35. two
  36. ;;
  37. c)
  38. three
  39. ;;
  40. h || help)
  41. usgae
  42. ;;
  43. *)
  44. error_message
  45. usage
  46. exit
  47. ;;
  48. esac
  49. done
  50. }
  51.  
  52. # ...
  53.  
  54. #-----------------------------------------------------------------------------#
  55. # MAIN
  56. #-----------------------------------------------------------------------------#
  57. main() {
  58.  
  59. }
  60.  
  61. #-----------------------------------------------------------------------------#
  62. # SCRIPT RUNTIME
  63. #-----------------------------------------------------------------------------#
  64.  
  65.  
  66. main
  67.  
  68. # SCRIPT END

Report this snippet  

You need to login to post a comment.