Email List: Xaustin-group-lX
[All Lists]

Re: $@ and set -u

To: David Korn <dgk@xxxxxxxxxxxxxxxx>
Subject: Re: $@ and set -u
From: Chet Ramey <chet.ramey@xxxxxxxx>
Date: Mon, 04 May 2009 09:35:10 -0400
Cc: austin-group-l@xxxxxxxxxxxxx, chet.ramey@xxxxxxxx
Organization: ITS, Case Western Reserve University
References: <200904301329.n3UDTOXH005366@xxxxxx>
David Korn wrote:
> cc:  chet.ramey@xxxxxx
> Subject: Re: Re: $@ and set -u
> --------
> 
>> David Korn wrote:
>>
>>> I do not think that set -u should cause an error.
>>>
>>> The original purpose of set -u is to locate typing errors in which a
>>> variable name is wrong.  When a script that works without set -u set, and
>>> fails with set -u not set, this is often used as an indication that
>>> the script has a bug.
>> I find it interesting that no version of ksh behaves that way.  Are we
>> standardizing existing practice, or new behavior?
>>
>> Here's the script I used to test my hypothesis:
>>
>> if [ $# -gt 0 ]; then
>>      shift $#
>> fi
>> set -u
>> echo "$@"
>> echo after
>>
>> The only shell that outputs "after" is dash.  For instance:
>>
>> $ ksh93 -c 'echo ${.sh.version}'
>> Version M 93t+ 2008-11-11
>> $ ksh93 ./x8
>> ./x8: line 5: @: parameter not set
>> $ ./bash --version
>> GNU bash, version 4.0.17(206)-maint (i386-apple-darwin9.4.0)
>> Copyright (C) 2009 Free Software Foundation, Inc.
>> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>>
>> This is free software; you are free to change and redistribute it.
>> There is NO WARRANTY, to the extent permitted by law.
>> $ ./bash ./x8
>> ./x8: line 5: $@: unbound variable
>>
>>
>>
>>
>> Chet
>> -- 
>> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>>
>> Chet Ramey, ITS, CWRU    chet@xxxxxx    http://cnswww.cns.cwru.edu/~chet/
>>
>>
> 
> My response only considered what the standard says and why set -u was
> added to the shell.  It didn't consider actual practice.
> 
> Going back to ksh88, and as Chet says, ksh93, -u applies to all parameters
> not just variables.  I don't have a copy of the original Bourne shell so
> I don't know what it did in practice.
> 
> Personally, I like the way it is in the standard and will change ksh93
> behavior to conform if there is concensus that the standard is correct
> as stands.  This way, a script that runs should not get error when
> invoked with sh -u unless there is a misspelled variable name or
> an uninitialized variable.
> 
> I will wait for a concensus to form before deciding to fix this.

There has been resolute silence for several days.  Do you think we have
consensus that the standard is correct as written, despite the
disconnection with historical practice?

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    chet@xxxxxx    http://cnswww.cns.cwru.edu/~chet/

<Prev in Thread] Current Thread [Next in Thread>