Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Why a '-quoted string isn't respected by // subst, while \-quoted is?
On Wed, Jan 25, 2023 at 12:05 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> Hi,
> I'm storing a pattern in a var:
>
> E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
>
> to then match it against:
>
> Q='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
>
> with // substitution:
>
> printf %s\\n $E $Q ${Q//$~E/q}
>
> The result is no match. However, if I instead quote the string with \:
>
> E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
You can print them to see the difference:
% E="0='\${\${\\(M\\)\${0::=\${\\(%\\):-%x}}:\\#/\\*}:-\$PWD/\$0}'"
% print -r -- $E
0='${${\(M\)${0::=${\(%\):-%x}}:\#/\*}:-$PWD/$0}'
% E='0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}'
% print -r -- $E
0=${${\(M\)${0::=${\(%\):-%x}}:\#/*}:-$PWD/$0}
As you can see, the first `E` has three extra characters: two quotes
and a backslash.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author