0
~ ᐅ docker image inspect nginx | jq .[].Config.ExposedPorts
zsh: no matches found: .[].Config.ExposedPorts

With bash it works as expected.

I found out a difference as to how the piping is interpreted in bash and zsh, but I can't say whether is has anything to do with my case.

Alexey Orlov
  • 111
  • 3
  • 1
    The problem is not the pipe, it's the unquoted glob pattern. In bash, glob expansion can be controlled with [`shopt`](https://www.gnu.org/software/bash/manual/bash.html#The-Shopt-Builtin) and its various `*glob*` settings. You need to investigate how zsh does it. – glenn jackman Jun 26 '21 at 14:26
  • 1
    tl;dr: quote the jq script: `jq '.[].Config.ExposedPorts'` – glenn jackman Jun 26 '21 at 14:27
  • Similar: [Zsh grep with glob * is not working](https://superuser.com/q/1651869/432690). The mechanism of the "problem" is the same. – Kamil Maciorowski Jun 26 '21 at 17:06

1 Answers1

3

Globbing also supports regex-like character group syntax. For example [a-f] matches a, b, … and f. It will only match a single letter. In your command, you have specified an empty group. It can never match anything.

In Bash, if a glob pattern doesn’t match anything, it is passed as-is on the command line. ZSH does not do this. Instead, it warns the user. You can change this: setopt nonomatch

tl;dr: Always quote your arguments if they contain anything but ASCII letters or numbers.

This Q/A on Stack Overflow has some more details.

Daniel B
  • 60,360
  • 9
  • 122
  • 163