Created
August 9, 2018 18:11
-
-
Save sgen/3112eab639541d838ed4676776f14190 to your computer and use it in GitHub Desktop.
Flags in bash
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 | |
flag_with_value=''; | |
flag_without_value=''; | |
while [[ "$#" -gt 0 ]]; | |
do | |
arg="$1"; | |
val="$2"; | |
case "$arg" in | |
-w|--flag-with-value) | |
flag_with_value="$val"; | |
shift; # shift the value off of args | |
;; | |
-o|--flag-without-value) | |
flag_without_value='true'; | |
;; | |
esac | |
shift; # shift the flag off of args | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment