You can use test -z option to check if an environment variable exists in Linux bash shell.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
export VAR1="hello world" if [[ -z "${VAR1}" ]] then echo "variable does not exists, do some action" else echo "variable exists, do some action" fi if [[ -z "${VAR2}" ]] then echo "variable does not exists, do some action" else echo "variable exists, do some action" fi |