I have this code:
if [[ ! -z "${ENV_OVERRIDE-}" ]]; then
CFG="some/path/$ENV_OVERRIDE.conf"
fi
It seems to be doing the same thing without the trailing dash/hyphen as well:
if [[ ! -z "${ENV_OVERRIDE}" ]]; then
CFG="some/path/$ENV_OVERRIDE.conf"
fi
What does the trailing dash do after all?
7
The dash in ${ENV_OVERRIDE-}
is used to provide a default value. If ENV_OVERRIDE
is unset then it takes the value that you write after.
For example here:
echo ${ENV_OVERRIDE-my_value}
If ENV_OVERRIDE
was unset, it would be assigned to my_value
. The reason why both of your codes are equivalent is because the default is an empty string.
1