Skip to content

Instantly share code, notes, and snippets.

@martinholub
Created October 10, 2018 11:25
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 martinholub/da30e4b4069071266d4729483fc441d8 to your computer and use it in GitHub Desktop.
Save martinholub/da30e4b4069071266d4729483fc441d8 to your computer and use it in GitHub Desktop.
Parse arguments in bash
# Parse Arguments --------------------------------------------------------------
# reference: https://stackoverflow.com/a/14203146
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-v|--vcf)
vcf="$2"
shift # past argument
shift # past value
;;
-b|--bam)
bam="$2"
shift # past argument
shift # past value
;;
-o|--output)
bam_noSNP="$2"
shift # past argument
shift # past value
;;
-c|--clip)
clip="$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
echo vcf = "${vcf}"
echo bam = "${bam}"
echo output = "${bam_noSNP}"
echo clip = "${clip}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment