cc: chet.ramey@case.edu
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@case.edu 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.
David Korn
dgk@research.att.com
|