Skip to content

Instantly share code, notes, and snippets.

@RHDZMOTA
Created May 8, 2020 20:22
Show Gist options
  • Save RHDZMOTA/054c710cb2e803641374b0f8cbdf78a4 to your computer and use it in GitHub Desktop.
Save RHDZMOTA/054c710cb2e803641374b0f8cbdf78a4 to your computer and use it in GitHub Desktop.
You can use the following function to check if an environment variable is set via parameter expansion. Early exit if it's not.
#!/usr/bin/env bash
function environ-check() {
local environ_tag="${1}"
local environ_val="${!1}"
if [[ -z "${environ_val}" ]]
then echo "Environ variable is not set ${environ_tag}"; exit 1
fi
}
environ-check ENVIRON_VARIABLE_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment