Skip to content

Instantly share code, notes, and snippets.

@dansalias
Created March 16, 2023 19:20
Show Gist options
  • Save dansalias/bb0b5157ae29812d1e7b6b3725a69627 to your computer and use it in GitHub Desktop.
Save dansalias/bb0b5157ae29812d1e7b6b3725a69627 to your computer and use it in GitHub Desktop.
Bash script with flags
#!/bin/bash
# usage:
# ./script.sh -a <value for a> -b <value for b>
while getopts a:b: opt
do
case $opt in
a) VAR_A=$opt;;
b) VAR_B=$opt;;
esac
done
: ${VAR_A:?missing flag -a}
: ${VAR_B:?missing flag -b}
echo $VAR_A $VAR_B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment