is_undefined UDEFINED
returns true, because the test inside is_undefined
doesn't test UNDEFINED
but $1
, and $1
is defined. It's value is UNDEFINED
.
So, your function should always return true, as long as you provide a parameter. The only time it will return false, should be when you call it with no arguments
is_undefined
To get is_undefined
test the actual variable, you can use variable indirection with an exclamation mark !
, see Shell Parameter Expansion
is_undefined ()
{
# aka "unset" (not to be confused with "set to nothing")
# http://stackoverflow.com/questions/874389/bash-test-for-a-variable-unset-using-a-function
[ -z "${!1+x}" ]
}