Guest User

Untitled

a guest
Feb 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. while getopts 'a:b:' opt; do
  4. case "$opt" in
  5. a) printf 'Got a: "%s"n' "$OPTARG" ;;
  6. b) printf 'Got b: "%s"n' "$OPTARG" ;;
  7. *) echo 'error' >&2
  8. exit 1
  9. esac
  10. done
  11.  
  12. shift $(( OPTIND - 1 ))
  13.  
  14. printf 'Other argument: "%s"n' "$@"
  15.  
  16. $ bash script.sh -a hello -- -b world
  17. Got a: "hello"
  18. Other argument: "-b"
  19. Other argument: "world"
Add Comment
Please, Sign In to add comment