Hi,

Current shells differ in how they split words in the arguments to
'export' and similar builtins:

A. Costa wrote:

>         % 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:

"$@" can be a pain, so for avoidance of confusion let's take another
example.

        $ foo() { export x=$1; }; foo "-f --c"
        export: 1: --c: bad variable name

The split in behaviors between shells for this construct is the same.

1. Variable expansions in what is grammatically a variable assignment
   or redirection do not undergo word splitting.  Variable expansions
   in command names and parameters do.[1]

2. According to the grammar, variable assignments must come before the
   command name.[2]

3. "export" is a special builtin, not a keyword, so grammatically it
   behaves just like any other command.[3]

So posh and dash would seem to be correct, and the foo=bar arguments
to 'export' should be split.

On the other hand, the suppression of word splitting in export, local,
and readonly arguments by bash, ksh, and pdksh is a nice behavior that
is not likely to break current scripts.  Would it make sense to tweak
the word splitting rules[1] to allow this behavior?

Looking forward to your thoughts,
Jonathan

[1] 
http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01
[2] 
http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02
[3] 
http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_14



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to