using /bin/sh how to check if environment variable is set.
The below command works for /bin/bash but not for /bin/sh
if [[ -v PROXY_PASS_MAPPING ]]; then echo "set" fi
what command will work for /bin/sh
using /bin/sh how to check if environment variable is set.
The below command works for /bin/bash but not for /bin/sh
if [[ -v PROXY_PASS_MAPPING ]]; then echo "set" fi
what command will work for /bin/sh
This solution should work for POSIX shell and bash:
if [ -n "$(printenv PROXY_PASS_MAPPING)" ]
then
echo The Variable is not empty and in the environment
fi
This does not catch the case where the variable is in the environment and empty. To test this, you can use
if printenv PROXY_PASS_MAPPING >/dev/null
then
echo The Variable is in the environment
else
echo The variable is not in the environment
fi