Advertisement
cd62131

Parse Option simple

May 23rd, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.53 KB | None | 0 0
  1. #!/bin/bash
  2. usage() {
  3.   echo "Usage: $0 [ -s | --server server1,server2 ] [ -t | --time YYYY-mmm-ddTHH:MM:SS ] ..."
  4.   exit 1
  5. }
  6. opt=$(getopt --options 's:t:h' --longoptions 'server:,time:,help' -- "$@")
  7. if (( $? )); then usage; fi
  8. eval set -- "${opt}"
  9. while :; do
  10.   case "$1" in
  11.     -s|--server) server="$2"; shift 2; ;;
  12.     -t|--time)   time="$2"; shift 2; ;;
  13.     -h|--help)   usage; ;;
  14.     --)          shift; break; ;;
  15.     *)           usage; ;;
  16.   esac
  17. done
  18. echo normal "$@"
  19. echo server "${server}"
  20. echo time "${time}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement