bug-bash
[Top][All Lists]
Advanced

[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: Chet Ramey
Subject: Re: bash does filename expansion when assigning to array member in compound form
Date: Wed, 22 Aug 2012 20:58:31 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0

On 8/20/12 5:12 PM, Dan Douglas wrote:
> On Monday, August 20, 2012 07:44:51 PM Roman Rakus wrote:
>> And how would you achieve to fill array with all file names containing 
>> `[1]=' for example.
> 
> $ ls
> [1]=a  [1]=b
> $ ( typeset -a a=( \[1\]=* ); typeset -p a )
> typeset -a a=('[1]=a' '[1]=b')
> $ ( typeset -a a=( [1]=* ); typeset -p a )
> typeset -a a=([1]='*')
> $
> 
> In ksh93, by escaping. I think this is what most people would expect and 
> probably what Bash intended.

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 means you can do things like

[{0,1,2,3}]=foo

to set the first four elements to the same value, but things like

f='more than one word'

x=( [0]=$f )

will still only set the first element.  This sounds like what you're after.

Chet

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