Bash subshells

I read Chapter 21. Subshells of The Linux Documentation Project‘s Advanced Bash-Scripting Guide. One fun trick I learned was using a subshell to test if a variable is set:

if (set -u; : $variable) 2> /dev/null
then
  echo "Variable is set."
fi

Leave a Reply