Skip to content

Instantly share code, notes, and snippets.

@sgen
Created August 9, 2018 18:11
Show Gist options
  • Save sgen/3112eab639541d838ed4676776f14190 to your computer and use it in GitHub Desktop.
Save sgen/3112eab639541d838ed4676776f14190 to your computer and use it in GitHub Desktop.
Flags in bash
#!/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