9951 explained code solutions for 126 technologies


bashHow to check if variable is set or unset


if [ -z ${variable+x} ]; then echo "\$variable is not set"; else echo "\$variable is set"; fictrl + c
variable

name of varible we're checking

echo "\$variable is not set"

will execute if variable is not set

echo "\$variable is set"

will execute if variable is set, even if it's empty (variable="")