This is a quick post to demonstrate how to use if statements in bash to check if we have the required environment variables in our environment before we continue a script.
Let’s say we require
BAR in our environment before we can continue, we can do this:
1 2 3 4 5 6 7 8 9 10 11
So now if
BAR is not set in our environment, the script will exit with return code 1.
To test it, when we pass no environment variables:
1 2 3
If we only pass one environment variable:
And as the result we want, when we pass both required environment variables, we have success: