Value of $? after unsetting non-existent shell variable
Hi all,
I just noticed something interesting. Let qqqqq represent some shell
variable that isn't defined. Then, on a system running sid:
bash$ unset qqqqq ; echo $?
0
bash$ zsh
zsh% unset qqqqq ; echo $?
1
zsh% dash
$ unset qqqqq ; echo $?
0
$ posh
$ unset qqqqq ; echo $?
1
$ sh # sh -> bash
sh-3.00$ unset qqqqq ; echo $?
0
Also, the version of bash (and sh, if pointing to bash) in woody returns
1 instead of 0.
This seems like it could lead to problems in "set -e" maintainer scripts
and other things. In my case (maybe I'm stupid?), I was happily using
"unset EXIT" in a shell script, only to find that it mysteriously failed
on woody, which prompted this bit of research. The shell script in
question is part of a Makefile in the cernlib build scripts. If bash
hadn't changed semantics between woody and sid, I don't know if my
sponsor or I would have caught this, potentially leading to an FTBFS on
some systems. This is a real-world problem.
So, who's right and who's wrong here? And if either return value is
acceptable, could it at least be made consistent between different shells?
regards,
--
Kevin B. McCarty <kmccarty@princeton.edu> Physics Department
WWW: http://www.princeton.edu/~kmccarty/ Princeton University
GPG public key ID: 4F83C751 Princeton, NJ 08544
Reply to: