18

I just encountered the following error with zsh when trying to use logcat.
Namely, when typing:

adb logcat *:D 

I get the following error in zsh

zsh: no matches found: *:D

I have to escape the * like :

adb logcat \*:D 

While using bash, I do not get the following error.
Why would it be like this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Patryk
  • 22,602
  • 44
  • 128
  • 244

4 Answers4

17

zsh warns you by default if you use a glob with no matches. Bash, on the other hand, passes the unexpanded glob to the app, which is a potential problem if you don't know for certain what will match (or if you make a mistake). You can tell zsh to pass the unevaluated argument like bash with setopt nonomatch:

   NOMATCH (+3) <C> <Z>
          If a pattern for filename generation has no  matches,  print  an
          error,  instead  of  leaving  it unchanged in the argument list.
          This also applies to file expansion of an initial `~' or `='.

Or drop the argument instead with setopt NULL_GLOB:

   NULL_GLOB (-G)
          If a pattern for filename generation has no matches, delete  the
          pattern  from  the  argument list instead of reporting an error.
          Overrides NOMATCH.

Bash actually has the same option (setopt nullglob), and can emulate zsh with setopt failglob

Kevin
  • 53,822
  • 15
  • 101
  • 132
  • `failglob`, not `nullglob`, I think. – Carl Norum Nov 17 '13 at 23:10
  • ... and just turning `NOMATCH` off in `zsh` will make it work like `bash`. – Carl Norum Nov 17 '13 at 23:11
  • @CarlNorum I actually did mean `nullglob`, but I've added `failglob` as well. And thanks for the `nomatch`, I was searching for `glob` and so it didn't come up. – Kevin Nov 17 '13 at 23:21
  • setting `setopt nonomatch` in my `.zshrc` helped – Patryk Nov 18 '13 at 00:29
  • There is fourth option not present in bash: `CSH_NULL_GLOB`: it is like `NOMATCH`, but fails only if all patterns fail (makes difference if there is more then one pattern). Guess `csh` has this behavior too (obvious from the option name), but I do not know how to make *bash* match this behavior. – ZyX Nov 29 '13 at 13:59
  • `unsetopt nomatch` seems to have the same effect as `setopt nonomatch`, and may be more readable – Zoey Hewll May 15 '18 at 02:46
2

bash does try to expand it - it's just that when it fails to match anything, it lets the * through to the program you're calling. zsh doesn't (at least by default).

You can make bash act like zsh by setting the failglob option. Conversely, you can make zsh work like the bash default by turning off the NOMATCH option.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
1

In terms of adb, no need to escape with backslashes. You can try

adb logcat '*:I'

Or an environment variable

export ANDROID_LOG_TAGS="*:I"
adb logcat
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
0

Short answer is: disable this by setopt nonomatch

(You can put it to ~/.zshrc) For more options, see @Kevin's answer.

Daniel Garmoshka
  • 5,849
  • 39
  • 40