Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Catch `setopt nounset`



Hi,

I'd to catch the call of a parameter that does not exist with `setopt 
nounset`.

```
setopt nounset

testfunc() {
printf "$DOESNOTEXIST\n"
}

if testfunc
then
    printf "no error\n"
else
    printf "error\n"
fi
```

This does not work. Neither the then nor else clause are entered. If 
I replace the `catch` statement with `if result=$(testfunc)` it 
prints "error". What am I missing here? Why does the latter work but 
not the former?

```
if result=$(testfunc)
then
    printf "no error\n"
else
    printf "error\n"
fi
```

Thorsten



Messages sorted by: Reverse Date, Date, Thread, Author