On Wed, Aug 02, 2006 at 01:20:44AM -0400, A. Costa wrote:
> In 'dash' try this:
> 
>         % foo() { export x="$@" ; }
>         % foo -f --c
>         export: 4: --c: bad variable name
>         % echo $?
>         2
> 
> It seems like it should be standard code.  
> 
> Remove 'export' from 'foo()' and there's no error:
> 
>       % foo() {  x="$@" ; } ; foo -f --c ; echo $?
>       0
> 
> I just tested the code in 'bash', 'ksh' and 'pdksh'; it works with no
> errors.  Yet in 'posh' it gives a different error:
> 
>       % posh
>       % foo() { export x="$@" ; } ; foo -f --c ; echo $?
>       export: invalid option -- -
>       1

Hi A., I don't think dash and posh are at fault here.

This is from
 
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_05_02

 @
     Expands to the positional parameters, starting from one. When the
 expansion occurs within double-quotes, and where field splitting (see
 Field Splitting) is performed, each positional parameter shall expand as
 a separate field, with the provision that the expansion of the first
 parameter shall still be joined with the beginning part of the original
 word (assuming that the expanded parameter was embedded within a word),
 and the expansion of the last parameter shall still be joined with the
 last part of the original word. If there are no positional parameters,
 the expansion of '@' shall generate zero fields, even when '@' is
 double-quoted.
 *
     Expands to the positional parameters, starting from one. When the
 expansion occurs within a double-quoted string (see Double-Quotes), it
 shall expand to a single field with the value of each parameter
 separated by the first character of the IFS variable, or by a <space> if
 IFS is unset. If IFS is set to a null string, this is not equivalent to
 unsetting it; its first character does not exist, so the parameter
 values are concatenated.

And the dash man page confirms that.

This means export x="$@" with $*="-f --c" will expand to export x=-f --c,
and dash's error message is quite right.  bash adds quotes in this case,
but you actually should use "$*" AFAICT, that's what it's for.

 $ dash -xc 'foo() {  export x="$@" ; } ; foo -f --c ; echo $?'
 + foo -f --c
 + export x=-f --c
 export: 1: --c: bad variable name
 $ bash -xc 'foo() {
 x="$@" ; } ; foo -f --c ; echo $?'
 + foo -f --c
 + x='-f --c'
 + echo 0
 0
 $ 

I'm about to close this bug, thanks, Gerrit.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to