Created
October 10, 2018 11:25
-
-
Save martinholub/da30e4b4069071266d4729483fc441d8 to your computer and use it in GitHub Desktop.
Parse arguments in bash
This file contains 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
# 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