bug-bash
[Top][All Lists]
Advanced

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

Re: bad double-quoted pattern substitution in indexed arrays


From: Chet Ramey
Subject: Re: bad double-quoted pattern substitution in indexed arrays
Date: Mon, 28 Feb 2011 22:40:23 -0500
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7

On 2/27/11 3:23 AM, Diego Augusto Molina wrote:

> Bash Version: 4.1
> Patch Level: 7
> Release Status: release
> 
> Description:
>   It's difficult to explain. Better see below the particular case I had.
> 
>   I needed to assign the elements of an array to other, but with a preceding
>   single quote. The following is a simplified (yet illustrative) example.
> 
>   declare -a array1=(a b c d e f) array2=()
>   array2=( "address@hidden/#/'}" )
> 
>   AFAIK (plus the man page), the syntax of pattern substitution is
>   ${parameter/pattern/string}, where "string" is just that, a string. I
> have also
>   tried the following:
> 
>   array2=( "address@hidden/#/"'"}" )
> 
>   But that caused a literal preceding "'", which technically is ok.
>   The ugly solution I had to take was a for loop. Nothing stressing but
> bothers.
> 
>   BASH shouldn't have treated specially the single quote after the slash and
>   before the closing brace (I think).

Maybe.  However, bash has always treated embedded quoted strings as
introducing a new `quoting context', even within double quotes.  This
has occasionally resulted in awkward constructs, of which this is
one.

FWIW, of the shells with arrays I had handy to test, ksh93 and mksh do
the same thing.  zsh behaves as you prefer.

Chet

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



reply via email to

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