From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: Shineru <theshinneru@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: tr [:lower:]
Date: Mon, 30 Aug 2021 21:39:15 -0400 [thread overview]
Message-ID: <YS2IQ96Qg0pYU5Ra@fullerene.field.pennock-tech.net> (raw)
In-Reply-To: <CAKik2nq8H-Uoy_vfdfrOmhToGozifOeCCQ=XGxTf8PU7XnT0Lg@mail.gmail.com>
On 2021-08-31 at 11:04 +1000, Shineru wrote:
> zsh 5.8.1. Arch GNU/Linux
>
> zsh: echo "hello" | tr [:lower:] [:upper:]
> zsh: no matches found: [:lower:]
setopt nonomatch
or: unsetopt nomatch
but: both of these are dangerous, because there's a real quoting issue
here.
% touch l p
% echo "hello" | tr [:lower:] [:upper:]
heppo
bash$ echo "hello" | tr [:lower:] [:upper:]
heppo
Without quoting,
[:lower:] matches any of: l o w e r :
[:upper:] matches any of: u p e r :
so the globbing turns the pipeline into:
echo "hello" | tr "l" "p"
By default, zsh complains about unmatched patterns, rather than letting
them fall through silently. Falling through leads to this sort of
"foot-gun" construct, where shells encourage you to do something which
"only works as long as X is not true", instead of having reliable code.
So you want, for safety, in any shell which resembles POSIX at all:
echo 'hello' | tr '[:lower:]' '[:upper:]'
(This probably belongs on zsh-users.)
-Phil
next prev parent reply other threads:[~2021-08-31 1:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 1:04 Shineru
2021-08-31 1:39 ` Phil Pennock [this message]
2021-09-01 14:53 ` Shineru
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=YS2IQ96Qg0pYU5Ra@fullerene.field.pennock-tech.net \
--to=zsh-workers+phil.pennock@spodhuis.org \
--cc=theshinneru@gmail.com \
--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).