Question: I am looking for a test that would return `true` if the environment variable is defined and has a value different than `0`, `false` or `NULL`.

```
ENABLE_SOMETHING=1
# or ENABLE_SOMETHING=true

if ... do ...

```

Note: under no circumstance the bash should complain about the variable not being defined or having a weird value, anything else than 0, empty, false, or not defined would be considered true.

Answer: 
I find these comparisons unuseful because they make appearance of code obscur and unobvious. I just use the nice feature of bash, that comes since v4.2, from the manpage:

```
   -v varname
          True if the shell variable varname is set (has been assigned a value).

```

Usage is very simple

```
OUTPUT_TO_LOG=1
if [ -v OUTPUT_TO_LOG ]; then
    exec > &>./logfile
    …
fi

```

In other words, to flag as enabled, just define. Try it!

```
$ :() { if [ -v VAR ]; then echo 'existed'; fi }
$ unset VAR && :          # no output
$ unset VAR && VAR= && :  # "existed"
$ unset VAR && VAR=1 && : # "existed"

```
You could do all three checks with regular expression matching (undefined parameters resolve to the empty string):

```
is_true() (
  shopt -s nocasematch
  [[ ! $1 =~ ^(false|0|)$ ]]
)

```