Last active
August 21, 2020 19:55
-
-
Save matthewoestreich/8d7ee33c8d33fb241520ce37edf71676 to your computer and use it in GitHub Desktop.
Example of how to use named params 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 | |
| # | |
| # 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