[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Assigning builtins behavior
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] Assigning builtins behavior |
Date: |
Mon, 8 Jan 2018 14:17:28 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 |
On 1/7/18 4:10 PM, Quentin L'Hours wrote:
> Hi,
>
> I've always thought builtins could not have a custom parsing, however it
> seems that export/readonly/declare/local (all the builtins creating an
> assignment) are able to disable field splitting when an assignment takes
> place, why is that? I know a simple assignment disables field splitting,
> but after all that's because the grammar states it should, but doesn't
> POSIX requires all simple commands to have the same splitting behavior?
No. Posix and bash include the concept of a `declaration command', as
described in
http://austingroupbugs.net/view.php?id=351
which dates from 2010.
This interpretation introduces the concept of a `declaration utility' and
specifies their behavior with respect to assignment statements as
arguments. In bash, declare, typeset, local, export, and readonly are all
declaration commands.
The basic idea of a declaration command is that arguments that can be
detected to be assignment statements are expanded the same way
`standalone' assignment statements are. That means the special tilde
expansions are performed and word splitting and filename generation
are not.
The above interpretation was approved in 2011, and will be effective
as of the next `major' release of the Posix standard (issue 8). At
that point, dash and other shell implementations that don't implement
this behavior will have to be changed to conform.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/