Skip to content

Instantly share code, notes, and snippets.

@jw-foss
Created September 27, 2018 10:05
Show Gist options
  • Save jw-foss/a2f9a4bd670be9d7176de1063f4009b2 to your computer and use it in GitHub Desktop.
Save jw-foss/a2f9a4bd670be9d7176de1063f4009b2 to your computer and use it in GitHub Desktop.
Parse through command line arguments
#!/usr/bin/env bash
# Parse command line arguments in a pattern like --flag value
while (( "$#" )); do
case "$1" in
-f|--flag)
statement
shift 2
;;
esac
done
# Parse command line arguments in a pattern like flag=value
for i in "$@"
do
case $i in
-f|--flag)
variable=${i#*=} # variable=value
shift
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment