Skip to content

Instantly share code, notes, and snippets.

@Chekote
Last active July 18, 2018 13:32
Show Gist options
  • Save Chekote/955d6d3e9d0bd8d781aa989675144c99 to your computer and use it in GitHub Desktop.
Save Chekote/955d6d3e9d0bd8d781aa989675144c99 to your computer and use it in GitHub Desktop.
How to parse arguments passed to a shell script
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-b|--branch) branch="$2" ;;
-t|--tag) tag="$2" ;;
--timeout) timeout="$2" ;;
*) break ;;
esac
shift 2
done
rest=("$@")
}
parse_args "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment