I searched this site with Google for an answer that explains how to test if a variable is set or not in a shell (I'm using bash, but I'd prefer the solution to be portable) in the strictest sense of the word, but I failed to find any results.
The problem is that the common answers do not actually check to determine whether a variable is set or not. Instead, they check to see if it is empty or not. If I type var=""
, then var
is set to an empty string. Nonetheless, it has still been set. Running [ -z "${var}" ]
will return true
despite the variable existing.
How do I test if a variable is set or not across various shells as opposed to just empty or not?