Skip to content

Instantly share code, notes, and snippets.

@aljp
Created August 8, 2019 00:20
Show Gist options
  • Save aljp/b3aff30c16abb3a7f73152f1ca2a4876 to your computer and use it in GitHub Desktop.
Save aljp/b3aff30c16abb3a7f73152f1ca2a4876 to your computer and use it in GitHub Desktop.
A example of parsing optional bash script arguments using a `--KEY=VALUE` syntax
# https://unix.stackexchange.com/a/353639
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
case "$KEY" in
STEPS) STEPS=${VALUE} ;;
REPOSITORY_NAME) REPOSITORY_NAME=${VALUE} ;;
*)
esac
done
echo "STEPS = $STEPS"
echo "REPOSITORY_NAME = $REPOSITORY_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment