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?



Ok, I'll take a closer look, however I'm now struggling with similar problem:

QE='0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'
print ${QE//'0=${${(M)${0::=${(%):-%x}}:#/*}:-$PWD/$0}'/°match°}

the strings in QE and in …//'…'/… are identical. Why no match? A simpler example works as expected:

QE=qeqe
print ${(S)QE//'qeqe'/°match°}

Output:

°match°

On Wed, 25 Jan 2023 at 12:36, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
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.


--
Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author