Le 24/07/2012 03:21, Cyrille Lefevre a écrit :

ping


Le 18/11/2009 09:34, David Korn a écrit :
cc:john.wier...@thomsonreuters.com
Subject: Re: [ast-developers] Set -o nounset fails when expanding "$@"
--------

That bug was fixed in ksh93t+.  It is listed in the RELEASE file as a bug
fix on 09-05-12.

09-05-12  To conform with POSIX, the -u option only checks for unset variables
           and subscript elements rather than checking for all parameters.


Hi,

I'm rereading the -developers ml archive, and this change looks wrong to me.

IMHO, "$@" should effectivelly not fail w/ no arg and set -u is set, but
$1 should fail w/ no arg.
in other words, it is important to exit on $1 if unset to make the
distinction on required and optional parameter.

the only reference I found in SUSv4 is :

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25

which says :

*-u*
    The shell shall write a message to standard error when it tries to
    expand a variable that is not set and immediately exit. An
    interactive shell shall not exit.

unfortunatelly, I found no rationale nor other reference.

ex. :

set -u

foo () {
         echo "$@"
         x=$1 y=${2-}
         echo $x:$y
}

foo 1
=> ok
foo
=> should not fail on "$@" which is allowed to be nothing,
      but should fail on $1 which is not set but a required parameter,
      should not fail on $2 which is an optional parameter.

ksh88 historically fails on "$@"
(d)ash, bash, mksh and zsh do it this way
posh and ksh93 fail nowhere

Regards,

Cyrille Lefevre
--
mailto:cyrille.lefevre-li...@laposte.net


_______________________________________________
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to