Created
April 12, 2020 20:19
-
-
Save justinsoliz/1f2d3a93c078cef93bda8c743ee0bc46 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash/29754866 | |
POSITIONAL=() | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
# set default values | |
DEFAULT=NO | |
case $key in | |
-d|--default) | |
DEFAULT=YES | |
shift # past argument | |
;; | |
-e|--extension) | |
EXTENSION="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-s|--searchpath) | |
SEARCHPATH="$2" | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
POSITIONAL+=("$1") # save it in an array for later | |
shift # past argument | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" # restore positional parameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment