From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: a='foo"'; echo ${a/foo"/"bar} outputs bar
Date: Sun, 11 Dec 2022 17:50:01 +0000 [thread overview]
Message-ID: <20221211175001.u7dqfrnnzylsbjan@chazelas.org> (raw)
$ 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
next reply other threads:[~2022-12-11 17:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-11 17:50 Stephane Chazelas [this message]
2022-12-13 6:21 ` Bart Schaefer
2023-08-07 2:36 ` Bart Schaefer
2023-10-04 4:20 ` Bart Schaefer
2023-10-17 16:44 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221211175001.u7dqfrnnzylsbjan@chazelas.org \
--to=stephane@chazelas.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).