Skip to content

Instantly share code, notes, and snippets.

@matthewoestreich
Last active August 21, 2020 19:55
Show Gist options
  • Select an option

  • Save matthewoestreich/8d7ee33c8d33fb241520ce37edf71676 to your computer and use it in GitHub Desktop.

Select an option

Save matthewoestreich/8d7ee33c8d33fb241520ce37edf71676 to your computer and use it in GitHub Desktop.
Example of how to use named params in bash
#!/bin/bash
#
# Use like:
# ./this-script.sh --container_name yourcontainername
#
printf '%s\n' "[NOTE] We assume you have a 'Dockerfile' at the root of this project"
container_name=${container_name:-}
# This allows us to use named params
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done
if [ -z "$container_name" ]; then
printf '%s\n' "[ERROR] '--container_name' parameter not found! Please supply a container name like: ./this-script.sh --container_name yourcontainername"
else
#
# DO WORK
#
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment