[Top][All Lists]

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

Re: bash does filename expansion when assigning to array member in compo

From: Dan Douglas
Subject: Re: bash does filename expansion when assigning to array member in compound form
Date: Wed, 29 Aug 2012 02:03:51 -0500
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

On Friday, August 24, 2012 09:38:44 AM you wrote:
> On 8/22/12 8:58 PM, Chet Ramey wrote:
> > Then how about this: words inside a compound assignment statement that are
> > recognized as assignment statements ([1]=foo) are expanded like assignment
> > statements (no brace expansion, globbing, or word splitting).  Other words
> > undergo all the expansions.

That's pretty much what I had in mind. I assumed this was how Bash handled 
pathname expansion until seeing Stephane's exception.

> > 
> > That means you can do things like
> > 
> > [{0,1,2,3}]=foo
> > 
> > to set the first four elements to the same value
> Or should these be marked as assignment statements after brace expansion,
> with the appropriate expansions performed?  It can be complicated to
> suppress brace expansion on the RHS after allowing it on the LHS.
> Chet

I can't think of any problems with either offhand. Even disabling brace 
expansion entirely for words recognized as assignments wouldn't be too bad.

But it could be a nice shortcut. Current methods I could think of using brace 
expansion are ugly:

 $ declare -a 'a+=(['{0..3}']=foo)' b[{0..3}]=foo c=( [{0..3}]=foo )
 $ declare -a "c=(${c[*]})"
 $ declare -p a b c
declare -a a='([0]="foo" [1]="foo" [2]="foo" [3]="foo")'

Dan Douglas

reply via email to

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