Checking for null string in bash

bash, linux

Solution

Nope, they are all the same. But couple of defensive habits to get into.

- You should quote the `$STRING` in the `-z` one as well

- If you are running with the -u option (I always do) then you should reference the possibly optional variable as `${STRING-}` just in case its not set at all

Problem

Is there any difference between the following tests? ``` [[ "$STRING" = "" ]] && exit 1; [[ "x$STRING" = "x" ]] && exit 1; [[ -z $STRING ]] && exit 1; ```

Original source