zsh-users
 help / color / mirror / code / Atom feed
* Catch `setopt nounset`
@ 2015-04-09 16:30 Thorsten Kampe
  2015-04-09 18:42 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Kampe @ 2015-04-09 16:30 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-10  1:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 16:30 Catch `setopt nounset` Thorsten Kampe
2015-04-09 18:42 ` Bart Schaefer
2015-04-10  1:11   ` Thorsten Kampe

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).