Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: quote parameter expansion from GLOB_SUBST
- X-seq: zsh-workers 35071
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Subject: Re: PATCH: quote parameter expansion from GLOB_SUBST
- Date: Sun, 10 May 2015 16:07:59 +0000
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=Ml9ZuuuAfWevmLjzp+zSWuxv+a4=; b=j43zx6 iOzFXCcDrprjD6tWeTkuMnHObP/vhc8MI3gzJoZDw2fMTJdqZYrlgnIdvzPv9jy+ k6ONUyA38u7S4lr7SRo5efH7Y1AqKzKI/35IQsbo0o0idPRsuwrJTfx1/jaoQCOA SCu67gJjiUeFSZTJPN8JWjcjQPuiyDKbHrF04=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=Ml9ZuuuAfWevmLjzp+zSWuxv+a4=; b=tD1S3 QdA2zfIUOZf+vN8gYtCok0+k18wDKkB5Cj5a00rqjhWHdgWRzn5hEQusA0xLbnvn h4y1ra9uxMxSBorwu5zLiY3LlSMXWjT6Bmef840HiFtoDXHiJLgPXLvislLnJJ+l rz+dNaTGzhMev3Y7/ZTkQ5pWEU0qJUJDD0/DiE=
- In-reply-to: <20150510004444.0f7d5444@ntlworld.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20150510004444.0f7d5444@ntlworld.com>
Peter Stephenson wrote on Sun, May 10, 2015 at 00:44:44 +0100:
> +item(tt(b))(
> +Quote with backslashes only characters that are special to pattern
> +matching. This is useful when the contents of the variable are to be
> +tested using tt(GLOB_SUBST), including the tt(${~)var(...)tt(}) switch.
> +
> +Quoting using one of the tt(q) family of flags does not work
> +for this purpose since quotes are not stripped from non-pattern
> +characters by tt(GLOB_SUBST). In other words,
> +
> +example(foo='a\ b'
> +[[ 'a b' = ${~foo} ]])
> +
> +fails, whereas
> +
> +example(foo='a\*b'
> +[[ 'a*b' = ${~foo} ]])
> +
> +succeeds. The tt(b) flag ensures the correct quoting.
> +)
Maybe state here that '[[ $foo == ${~${(b)foo}} ]]' is always true (like
the code comments already state)? That way the doc will have an example
of using the (b) modifier, not just an example of how using (q) doesn't
work :-)
Speaking of which, it's not immediately clear when reading the above
example that 'a\ b' and 'a\*b' are ${(q):-"a b"} and ${(q):-"a*b"}; if
that example remains, I would suggest stating that more explicitly.
So, overall:
+Quoting using one of the tt(q) family of flags does not work
+for this purpose since quotes are not stripped from non-pattern
+characters by tt(GLOB_SUBST). In other words,
+
+example(pattern=${(q)str}
+[[ $str = ${~pattern} ]])
+
+works if tt($str) is tt('a*b') but not if it is tt('a b'), whereas
+
+example(pattern=${(b)str}
+[[ $str = ${~pattern} ]])
+
+is always true for any possible value of tt($str).
+)
Cheers,
Daniel
> /*
> + * Only quote pattern characters.
> + * ${(b)foo} guarantees that ${~foo} matches the string
> + * contained in foo.
> + */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author