Help us complete this page with more examples of validation.
Variables
The simplest validation is as follows:
if [[ "$variable" ]]; then
echo "set"
else
echo "unset"
fi
It checks if a variable is set.
Beware, if you want to validate the value of the variable, you'll have to be more explicit:
variable=0
if [[ $variable ]]; then
echo "This gets printed because the variable is set."
elif [[ $variable == 1 ]]; then
echo "This does not get printed because the variable equals 0."
fi