cc: agco...@gis.net 381...@bugs.debian.org
Subject: Re: Word splitting in 'export' arguments (Re: bash: expands $@ within  
double-quotes inconsistently)
--------

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

This looks like an omission in the standard.  The man page for ksh88
(one of the historical shells that the standard is based on),
documents this behavior for export, readonly, and typeset. 

The following is in the ksh88 man page:
===============cut here=========================
Words that are in the format of a parameter assignment,
are expanded with the same rules as a parameter assignment.
This means that
tilde substitution is performed after the
.B =
sign and word splitting and file name generation are not
performed.
===============cut here=========================

It would make senset to allow this behavior and even more sense to
require it.


David Korn
d...@research.att.com



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