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. Reproducible: Always Steps to Reproduce: 1.declare -a my_array=(a b c d e) 2.echo "${my_array[@]/#/'}" Actual Results: Nothing actually, just the PS2 wating for a closing single quote. Expected Results: 'a 'b 'c 'd 'e 'f BASH shouldn't have treated specially the single quote after the slash and before the closing brace.
Possible workaround: $ q="'" $ echo "${my_array[@]/#/$q}" 'a 'b 'c 'd 'e
(In reply to comment #1) > Possible workaround: > > $ q="'" > $ echo "${my_array[@]/#/$q}" > 'a 'b 'c 'd 'e > Thanks a lot Ulrich, I didn't thought about that. It really simplifies the code. I have sent a bug report to the developers.
Chet Ramey answered my e-mail (reporting the bug) and here's what he said: >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. I assume this behaviour is intentional. Thus, closing the bug as invalid.