[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "unset" return value wrong
From: |
Chet Ramey |
Subject: |
Re: "unset" return value wrong |
Date: |
Tue, 17 Oct 2000 14:41:49 -0400 |
> The exit status of the "unset" shell built-in should be 0 if given any
> unsettable variable, whether or not the variable needed to be unset.
I disagree, and so do other versions of sh which claim POSIX
compliance that I was able to test (ksh93, FreeBSD sh, pdksh). The
Solaris /bin/sh returns 0, but /usr/xpg4/bin/sh returns 1.
> In bash 2.04, unset returns 1 if the variable wasn't set to begin with.
> This isn't the correct criterion according to Posix, and it broke a
> shell script of mine that didn't expect that behavior.
The section of POSIX.2 to which I think you're referring says:
Unsetting a variable or function that was not previously set
shall not be considered an error and shall not cause the shell
to abort.
I contend that this actually refers to the text at the beginning of
section 3.14, which says that the shell shall abort if a syntax error
is encountered in any of the special builtin utilities.
> Furthermore, "help unset" claims that PATH and IFS cannot be unset.
> After reading that, I would expect "unset PATH" to not unset PATH and
> to return 1. Instead it does unset PATH and returns 0.
Thanks, this has been fixed. It was a historical artifact. PATH and
IFS are unsettable, unless they have been made readonly.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)
Chet Ramey, CWRU chet@po.CWRU.Edu http://cnswww.cns.cwru.edu/~chet/