Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: modify or delete variable



On Sun, Apr 7, 2024 at 9:24 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2024-04-07 01:10, Lawrence Velázquez wrote:
> > var=(${${(M)var:#*(#i)$substring*}//(#bi)($substring)/aaa${match[1]}bbb})
> >
> Yeah, nesting like that would have to work.  It's hard on the eyes at
> first  but the step by step substitution logic is there.  But I wonder
> why this doesn't work:
>
>      var=( ${(M)var//(#bi)($substring)/aaa${match[1]}bbb} )

It doesn't work because the (M) flag only applies to the ${...#...} or
${...%...} replacements.  This is documented.

> ... seems to me the (M) would have the same function -- if the substring isn't there to be matched it can't be modified so kill the line.

That doesn't make sense in any case -- (M) means "include the matched
string", that is, reverse the effect of the :# operator which means
"delete the matching value".  What's the "reverse" of "replace A with
B anywhere"?  Certainly not "delete everything".




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