Created
October 23, 2019 03:41
-
-
Save nhtzr/deac822a7118d29e9136cc3a858a96f4 to your computer and use it in GitHub Desktop.
getenv with default 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
#!/usr/bin/env bash | |
set -euo pipefail | |
key="${1:?Env var is required as first parameter}" | |
default=${2:-} | |
value="${!key:-$default}" | |
: "${value:?Env var $key not found}" | |
printf "%s" "${value}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment