Combreal

bash_template.sh

Jun 23rd, 2021
782
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. usage="$(basename "$0") [-h] [-s n] -- program to calculate the answer to life, the universe and everything
  2.  
  3. where:
  4.    -h  show this help text
  5.    -s  set the seed value (default: 42)"
  6.  
  7. seed=42
  8. while getopts ':hs:' option; do
  9.   case "$option" in
  10.     h) echo "$usage"
  11.        exit
  12.        ;;
  13.     s) seed=$OPTARG
  14.        ;;
  15.     :) printf "missing argument for -%s\n" "$OPTARG" >&2
  16.        echo "$usage" >&2
  17.        exit 1
  18.        ;;
  19.    \?) printf "illegal option: -%s\n" "$OPTARG" >&2
  20.        echo "$usage" >&2
  21.        exit 1
  22.        ;;
  23.   esac
  24. done
  25. shift $((OPTIND - 1))
RAW Paste Data