If you don't care about the difference between an unset variable or a variable with an empty value, you can use the default-value parameter expansion:
foo=${DEPLOY_ENV:-default}
If you do care about the difference, drop the colon
foo=${DEPLOY_ENV-default}
You can also use the -v
operator to explicitly test if a parameter is set.
if [[ ! -v DEPLOY_ENV ]]; then
echo "DEPLOY_ENV is not set"
elif [[ -z "$DEPLOY_ENV" ]]; then
echo "DEPLOY_ENV is set to the empty string"
else
echo "DEPLOY_ENV has the value: $DEPLOY_ENV"
fi