Skip to content

Instantly share code, notes, and snippets.

@justinsoliz
Created April 12, 2020 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinsoliz/1f2d3a93c078cef93bda8c743ee0bc46 to your computer and use it in GitHub Desktop.
Save justinsoliz/1f2d3a93c078cef93bda8c743ee0bc46 to your computer and use it in GitHub Desktop.
#!/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