---
# System prepended metadata

title: Test if variable is empty or not set in bash

---

Test if variable is empty or not set in bash
============================================

``` bash
if [ -z "${VAR+xxx}" ] || [ -z "$VAR" ]; then 
    echo VAR is not set or empty;
fi
```

## Tests

``` bash
check () {
    local VAR=$1
    if [ -z "${VAR+xxx}" ] || [ -z "$VAR" ]; then 
        echo VAR is not set or empty;
    fi
}

➜ unset VAR
➜ check $VAR
VAR is not set or empty

➜ VAR=""
➜ check $VAR
VAR is not set or empty

➜ VAR="foo"
➜ check $VAR

```
