A simple template to create bash scripts for running jobs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

myscript 1.5KB

  1. #!/bin/bash
  2. # HELP SECTION
  3. help_msg(){
  4. echo ""
  5. if [ "${1+xxx}" ];
  6. then
  7. echo -e $1
  8. echo ""
  9. fi
  10. echo -e "\e[36m\e[1m__My Script__\e[0m"
  11. echo ""
  12. echo "An example template for making your own bashscripts."
  13. echo ""
  14. echo -e "\e[38;5;222mUsage Instructions:\e[0m"
  15. echo ""
  16. echo -e " \e[92moption1\e[0m"
  17. echo "Do something 1."
  18. echo -e " \e[92moption2\e[0m"
  19. echo "Do something 2."
  20. echo -e " \e[92moption3\e[0m"
  21. echo "Do something 3."
  22. echo -e "\e[38;5;222mOptional args:\e[0m"
  23. echo ""
  24. echo -e " \e[92m-h\e[0m"
  25. echo " Help and documentation."
  26. echo ""
  27. }
  28. help(){
  29. help_msg
  30. echo ""
  31. echo -e "\e[1mHelp Text\e[0m"
  32. echo -e "Lorem ipsum dolor sit amet, consectetur adipisicing elit.\nQuia libero voluptatum veniam laudantium corporis, illo enim"
  33. echo -e "\nipsa ut voluptatem similique possimus delectus vitae quisquam.\nDistinctio molestias dolor,"
  34. echo -e "\nsuscipit doloremque ipsa."
  35. exit 1;
  36. }
  37. if [[ $# -eq 0 ]] ; then
  38. help_msg
  39. exit 1;
  40. fi
  41. option1_function(){
  42. # Replace with custom logic
  43. echo "option 1 used"
  44. }
  45. option2_function(){
  46. # Replace with custom logic
  47. echo "option 1 used"
  48. }
  49. option3_function(){
  50. # Replace with custom logic
  51. echo "option 1 used"
  52. }
  53. # OPTION SECTION
  54. while [ $# -gt 0 ]
  55. do
  56. case "$1" in
  57. option1) option1_function;;
  58. option2) option2_function;;
  59. option3) option3_function;;
  60. # Add more if you like
  61. -h) help;;
  62. *)
  63. # help_msg "\e[31m\e[1mWrong arguments!\e[0m"
  64. echo ""
  65. echo -e "\e[31m\e[1mInvalid Option, use -h flag for help.\e[0m"
  66. echo ""
  67. exit 1;
  68. break;
  69. esac
  70. shift
  71. done