Created
September 27, 2018 10:05
-
-
Save jw-foss/a2f9a4bd670be9d7176de1063f4009b2 to your computer and use it in GitHub Desktop.
Parse through command line arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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