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

a='foo"'; echo ${a/foo"/"bar} outputs bar



$ a='foo"'
$ echo ${a/foo"/"bar}
bar

Whether quotes should escape the "/" is not clearly documented,
though the doc does tell us to use backslash for that.

However the fact that the first " is taken as being part of the
pattern while the second one is removed doesn't make much sense.

In ksh93, bash and mksh, quotes can be used to escape the /,
i.e. one can do:

$ a='/x/y/z' bash -c 'echo "${a/"/y/"/+}"'
/x+z
$ a='/x/y/z' ksh -c 'echo "${a/"/y/"/+}"'
/x+z
$ a='/x/y/z' mksh -c 'echo "${a/"/y/"/+}"'
/x+z

Maybe zsh could align with them?

The csh-style one looks better:

$ a='foo"' zsh -c 'echo ${a:s/foo"/"bar}'
bar"

quotes don't escape the / either but at least the " is to taken  as part of the
pattern.

Better than tcsh anyway:

$ a='foo"' tcsh -c 'echo ${a:s/foo"/"bar}'
^C^C^C^Z
zsh: suspended  a='foo"' tcsh -c 'echo ${a:s/foo"/"bar}'
(148)$ kill %

(ended up using all my RAM).

-- 
Stephane





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