zsh-workers
 help / color / mirror / Atom feed
* tr [:lower:]
@ 2021-08-31  1:04 Shineru
  2021-08-31  1:39 ` Phil Pennock
  0 siblings, 1 reply; 3+ messages in thread
From: Shineru @ 2021-08-31  1:04 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 103 bytes --]

zsh 5.8.1. Arch GNU/Linux

zsh: echo "hello" | tr [:lower:] [:upper:]
zsh: no matches found: [:lower:]

[-- Attachment #2: Type: text/html, Size: 143 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: tr [:lower:]
  2021-08-31  1:04 tr [:lower:] Shineru
@ 2021-08-31  1:39 ` Phil Pennock
  2021-09-01 14:53   ` Shineru
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 2021-08-31  1:39 UTC (permalink / raw)
  To: Shineru; +Cc: zsh-workers

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: tr [:lower:]
  2021-08-31  1:39 ` Phil Pennock
@ 2021-09-01 14:53   ` Shineru
  0 siblings, 0 replies; 3+ messages in thread
From: Shineru @ 2021-09-01 14:53 UTC (permalink / raw)
  To: Shineru, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1195 bytes --]

Thanks!

вт, 31 авг. 2021 г. в 11:39, Phil Pennock <
zsh-workers+phil.pennock@spodhuis.org>:

> 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
>

[-- Attachment #2: Type: text/html, Size: 1694 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-01 14:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31  1:04 tr [:lower:] Shineru
2021-08-31  1:39 ` Phil Pennock
2021-09-01 14:53   ` Shineru

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ https://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git