[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: |
Stephane Chazelas |
Subject: |
Re: bash does filename expansion when assigning to array member in compound form |
Date: |
Tue, 21 Aug 2012 07:24:31 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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 "=".
$ touch {3..5}=foo
$ ls
3=foo 4=foo 5=foo
$ bash -c 'a=([0-9]=*); typeset -p a'
bash: [0-9]=*: bad array subscript
declare -a a='()'
$ bash -c 'shopt -s extglob; a=(@([0-9])=*); typeset -p a'
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `shopt -s extglob; a=(@([0-9])=*); typeset -p a'
$ bash -c 'shopt -s extglob
a=(@([0-9])=*); typeset -p a'
declare -a a='([0]="3=foo" [1]="4=foo" [2]="5=foo")'
> 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.
Quoting them will prevent both, it become more tricky if you
want only one or the other.
Note that in bash that also means we need to quote variables in
there even if IFS is set to "".
$ bash -c 'a="*"; b=([1]=$a); typeset -p b'
declare -a b='([0]="[1]=bar")'
--
Stephane
- Re: bash does filename expansion when assigning to array member in compound form, (continued)
- Message not available
- Re: bash does filename expansion when assigning to array member in compound form, Gundi Cress, 2012/08/20
- Re: bash does filename expansion when assigning to array member in compound form, Roman Rakus, 2012/08/20
- Re: bash does filename expansion when assigning to array member in compound form, Dan Douglas, 2012/08/20
- Re: bash does filename expansion when assigning to array member in compound form, Chet Ramey, 2012/08/22
- Re: bash does filename expansion when assigning to array member in compound form, Chet Ramey, 2012/08/24
- Re: bash does filename expansion when assigning to array member in compound form, Dan Douglas, 2012/08/29
- Re: bash does filename expansion when assigning to array member in compound form, Chet Ramey, 2012/08/29
- Re: bash does filename expansion when assigning to array member in compound form,
Stephane Chazelas <=
- Re: bash does filename expansion when assigning to array member in compound form, Dan Douglas, 2012/08/21