Advertisement
cd62131

Parse Option

May 23rd, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. #!/bin/bash
  2. typeset -a argv
  3. typeset -a server
  4. typeset -a time
  5. ((server_p = 0))
  6. ((time_p = 0))
  7. while (($# > 0)); do
  8.   if ((server_p)); then
  9.     case "$1" in
  10.       -*) ((server_p = 0)); ;;
  11.       *)  server=("${server[@]}" "$1"); shift; ;;
  12.     esac
  13.     continue
  14.   fi
  15.   if ((time_p)); then
  16.     case "$1" in
  17.       -*) ((time_p = 0)); ;;
  18.       *)  time=("${time[@]}" "$1"); shift; ;;
  19.     esac
  20.     continue
  21.   fi
  22.   case "$1" in
  23.     -h) ((server_p = 1)); shift; ;;
  24.     -t) ((time_p = 1)); shift; ;;
  25.     *)  argv=("${argv[@]}" "$1"); shift; ;;
  26.   esac
  27. done
  28. if [[ ! -z ${time[0]} ]] && ((${#time[@]} > 2)); then
  29.   echo time error
  30. fi
  31. echo normal "${argv[@]}"
  32. echo server "${server[@]}"
  33. echo time "${time[@]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement