[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assignments preceding "declare" affect brace and pathname expansion.

From: Chet Ramey
Subject: Re: Assignments preceding "declare" affect brace and pathname expansion.
Date: Tue, 26 Mar 2013 20:33:52 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130216 Thunderbird/17.0.3

On 3/25/13 9:44 PM, Dan Douglas wrote:
> Hi,
>     $ set -x; foo=bar declare arr=( {1..10} )
>     + foo=bar
>     + declare 'a=(1)' 'a=(2)' 'a=(3)' 'a=(4)' 'a=(5)'
>     $ touch xy=foo
>     $ declare x[y]=*
>     + declare 'x[y]=*'
>     $ foo=bar declare x[y]=*
>     + foo=bar
>     + declare xy=foo
> This isn't the same bug as the earlier a=([n]=*) issue. Each word (the entire
> assignment) is subject to globbing. "let", "eval", and possibly other builtins
> appear to randomly use this same kind of expansion regardless of whether they 
> are preceded by an assignment, though I can't think of any uses for it. 
> Arguments in this case are treated neither as ordinary assignments
> nor ordinary expansions.

Bash understands the concept of a `declaration command'.  These are
essentially builtins that take assignment statements as arguments.  Bash
does its best to identify declaration commands and expand their arguments
as if they were assignment statements.  If it can't identify commands as
such, arguments are expanded as normal and then treated as the command
does its arguments.  Aliases are one way to disguise declaration commands;
preceding them with variable assignments is another.

Posix does a better job of explaining the whole concept:


I believe this is a part of TC1 to Posix-2008, since the interpretation was
approved back in 2011.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]