Knowledge Garden

Search

Search IconIcon to open search

Check if Env Var Exists

Last updated Nov 2, 2022 Edit Source

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
if span> -z &; then
  MY_SCRIPT_VARIABLE="Some default value because DEPLOY_ENV is undefined"
else
  MY_SCRIPT_VARIABLE="${DEPLOY_ENV}"
fi

# or using a short-hand version

span> -z & && MyVar='default' || MyVar="${DEPLOY_ENV}"

# or even shorter use

MyVar="${DEPLOY_ENV:-default_value}"