Why zsh tries to expand * and bash does not?

a 夏天 提交于 2019-12-03 11:30:45

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

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!