9951 explained code solutions for 126 technologies


bashHow to check if variable is empty


if [ -z "$variable" ]; then echo "\$variable is empty"; else echo "\$variable is not empty"; fictrl + c
if [ -z "$variable" ]

check if $varible is empty

echo "\$variable is empty"

will execute if variable is empty or unset

echo "\$variable is not empty"

will execute if variable is not empty (has some value)