Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: tr [:lower:]
- X-seq: zsh-workers 49336
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: Shineru <theshinneru@xxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: tr [:lower:]
- Date: Mon, 30 Aug 2021 21:39:15 -0400
- Archived-at: <https://zsh.org/workers/49336>
- In-reply-to: <CAKik2nq8H-Uoy_vfdfrOmhToGozifOeCCQ=XGxTf8PU7XnT0Lg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Shineru <theshinneru@xxxxxxxxx>, zsh-workers@xxxxxxx
- Openpgp: url=https://www.security.spodhuis.org/PGP/keys/keys-2013rsa-2020cv25519.asc
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author