From: Icarus Sparry on
On Mon, 14 Dec 2009 17:28:39 +0000, Dave wrote:

> Icarus Sparry wrote:
>> On Mon, 14 Dec 2009 17:05:52 +0000, Dave wrote:
>>
>>> I have a shell script written by someone else, which starts
>>>
>>>
>>> #!/usr/bin/env bash
>>>
>>>
>>> then has the line:
>>>
>>> unset DISTUTILS_DEBUG
>>>
>>> It's a bit pointless, as DISTUTILS_DEBUG is not set in the script, but
>>> there is some code commented out, where is was obviously set at one
>>> time.

> bash-2.04$ bash --version
> GNU bash, version 2.04.0(1)-release (hppa2.0w-hp-hpux11.00) Copyright
> 1999 Free Software Foundation, Inc. bash-2.04$
>
> Is this likely to be a problem with HP-UX, or bash? The bash command is
>
> /opt/OpenSource/bin/bash
>
> so from the location, one might guess HP do not support 'bash'
>
> I appreciate a newer version of bash might not suffer this problem, but
> I'd rather sort out issues which occur with old versions of commands too
> - not everyone runs the latest. The code I am using is checked by quite
> a few people on the more common linux and OS X distributions, so most
> people will not find issues like this.

By an unhappy chance I happen to have a bash-2.04 system at hand, and it
also returns '1' if you unset a variable that is not set, so it looks to
be a bash bug.

bash 2.04 dates from March 2000.

If you remove the "set -e" that you added then there would not be an
issue. You could put a "set +e" and "set -e" pair around the "unset" as
another way to work around the issue.
From: OldSchool on
>> Is this behavior to be expected? It does not happen under OS X, Linux or
>> Solaris, but is causing a problem on HP-UX 11.11.

>>
>>
>> Dave
>>
>>
>
> Looking at POSIX 2004,
>
> http://www.opengroup.org/onlinepubs/009695399/utilities/unset.html
>
> it says:
>
> "Unsetting a variable or function that was not previously set shall not be
> considered an error and does not cause the shell to abort."
>
> so it looks like this is a place where HP-UX is not POSIX 2004 compatible.
>

I'd be more inclined to say that the version of the bash shell installed on
the HP-UX system is not compliant. HP doesn't ship bash with HP-UX, so
somebody added it to the system in question. as Icarus noted, this is a
very old version, and it probably should be updated.

From: Stephane CHAZELAS on
2009-12-14, 17:05(+00), Dave:
[...]
> unset DISTUTILS_DEBUG
>
> It's a bit pointless, as DISTUTILS_DEBUG is not set in the script, but there is
> some code commented out, where is was obviously set at one time.
>
> I've added
>
> set -e
[...]

That was fixed in bash-2.05b-beta1. 2.05b was released in 2002.
The latest version of bash is 4.0.35. You may want to consider
upgrading.

--
St�phane
From: Stephane CHAZELAS on
2009-12-14, 17:20(+00), Icarus Sparry:
[...]
>> unset DISTUTILS_DEBUG
[...]
> The normal way is to use the
> ${DISTUTILS_DEBUG+yes}
> variable expansion. This will evaluate to "yes" if the variable is set,
> even if it is the zero length string, and nothing otherwise.
>
> So hopefully
> test -z "${DISUTILE_DEBUG+yes} && unset DISTUTILS_DEBUG
> will fix your problem. What version of bash are you running on your HP-UX
> machine?

The common way to make a command immune to set -e is to write
it:

unset DISTUTILS_DEBUG || : OK

Best is not to use "set -e" and add "|| exit" where relevant
(or any other corrective/alternative action, or use if/then...).
The behavior of set -e is not consistent from one shell to the
other and is hard to guess intuitively in corner (and not so
corner) cases (as in subshells, pipes, functions, compound
commands, dotted scripts...)


--
St�phane
From: Dave on
Stephane CHAZELAS wrote:
> 2009-12-14, 17:05(+00), Dave:
> [...]
>> unset DISTUTILS_DEBUG
>>
>> It's a bit pointless, as DISTUTILS_DEBUG is not set in the script, but there is
>> some code commented out, where is was obviously set at one time.
>>
>> I've added
>>
>> set -e
> [...]
>
> That was fixed in bash-2.05b-beta1. 2.05b was released in 2002.
> The latest version of bash is 4.0.35. You may want to consider
> upgrading.
>

I could easily upgrade - in fact, there is a later version someone else built on
the machine.

But it does no harm to find out issues that arise as a result of using older
versions of software. The release of HP-UX is quite old, but it is the latest
which will work on the PA-RISC processor. The newer releases only work on Itanium.

Dave

--
I respectfully request that this message is not archived by companies as
unscrupulous as 'Experts Exchange' . In case you are unaware,
'Experts Exchange' take questions posted on the web and try to find
idiots stupid enough to pay for the answers, which were posted freely
by others. They are leeches.