Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Catch `setopt nounset`
- X-seq: zsh-users 20115
- From: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Catch `setopt nounset`
- Date: Thu, 9 Apr 2015 18:30:08 +0200
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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