[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: Tue, 21 Aug 2012 03:48:31 -0500
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

On Tuesday, August 21, 2012 07:24:31 AM Stephane Chazelas wrote:
> 2012-08-20 19:44:51 +0200, Roman Rakus:
> [...]
> > And how would you achieve to fill array with all file names
> > containing `[1]=' for example.
> [...]
> Another interesting question is how to fill the array with all
> the file names that start with a digit followed by "=".
> a=(@([0-9])=*); typeset -p a'
> declare -a a='([0]="3=foo" [1]="4=foo" [2]="5=foo")'

Another way:
IFS= glob=[123]=* typeset -a 'y=($glob)'

And another:
IFS= typeset -a "a=($(printf '%q ' [123]=*))"

Or set -A if available.

> > Definitely it's good, if you want to be sure, to always quote all
> > characters which means pathname expansion - `*', `?' and `['.
> [...]
> Yes, the problem here is that "[" is overloaded in a conflicting
> manner as a globbing operator and that poorly designed special
> type of array assignment.

Indeed, but you were right in calling a bug. Matching weird filenames is an odd 
corner-case for which there are work-arounds. The current behavior doesn't 
make sense.

Still, a variable/function attribute for disabling pathname expansion in a 
controled manner would be useful given that having to manage the state of set 
-f mostly precludes its use.

Dan Douglas

reply via email to

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