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

Let's do it RE: Should we backup this change? RE: Modifier substitutions.



>
> The change went in in 6002.  It was followed in 6003 by a
> change to allow
> a leading double backslash to escape the delimiter.  So all
> you need to
> do is change uses of ${foo/$bar/...} into ${foo/\\$bar/...}
> to avoid the
> confusion.  And without 6002, there's no way to build up an anchored
> pattern in a variable (which was Andrej's original complaint).
>
> Also, though I'm the last person to argue for keeping a
> change solely for
> compatibility, bash recognizes the same syntaxes.
>


Unfortunately, it is so inconsistent, that I really suggest to backup
it. Look here:

from Zsh manual (example for ${.../.../...})

          foo="twinkle twinkle little star" sub="t*e" rep="spy"
          print ${foo//${~sub}/$rep}
          print ${(S)foo//${~sub}/$rep}

but

bor@itsrm2% foo=foo
bor@itsrm2% foopat='#foo'
bor@itsrm2% print ${foo/$~foopat/bar}
zsh: bad pattern: #foo
bor@itsrm2% print ${foo/$foopat/bar}
bar
bor@itsrm2% if [[ $foo == $~foopat ]]; then print yes; else print no; fi
zsh: bad pattern: #foo

Looking at the _arguments, there is no ~ flag either:

    # ... and add "same" options

    while (( $#sopts )); do
      lopts=( $lopts ${lopts/$sopts[1]/$sopts[2]} )
      shift 2 sopts
    done


So, currently

- example in manual is wrong. Or, better said, it _is_ correct because
#foo is invalid pattern - but, then, how _arguments work currently?
Well, they work because there is no metachars in pattern (the only use
is _configure). So, this is wrong anyway.

- any way to fix it will lead to inconsistency - #foo will match `foo'
in replacement, but not anywhere else.

- nobody really expects run native bash scripts with zsh.

- this "anchoring in pattern" is needed in probably 1% of all cases -
forcing use of `\\' in 99%. That is weird. And if anybody needs
anchoring - (#s) is there.

So, my strong suggestion - let's backup it, and for the time being use
(#s) in _configure (I actually do not like these "same" arguments
anyway - it does not work reliably, sigh)

-andrej



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