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=( "${array1[@]/#/'}" )
>
> 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=( "${array1[@]/#/"'"}" )
>
> 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 [email protected] http://cnswww.cns.cwru.edu/~chet/