为什么zsh尝试扩展*而bash不扩展? [英] Why zsh tries to expand * and bash does not?

查看:101
本文介绍了为什么zsh尝试扩展*而bash不扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用logcat时,我刚遇到 zsh 的以下错误。

即键入时:

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

adb logcat *:D 

我在zsh中遇到以下错误

I get the following error in zsh

zsh: no matches found: *:D

我必须像这样逃避 *

adb logcat \*:D 

使用bash时,没有出现以下错误。

为什么会这样?

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

推荐答案

zsh 默认情况下会警告您,如果您使用没有匹配项的glob。另一方面,Bash会将未扩展的Glob传递给应用程序,如果您不确定什么将匹配(或者如果您出错),则可能会出现问题。您可以告诉zsh通过 setopt nonomatch 传递bash之类的未经评估的参数:

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 `='.

或者使用 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实际上具有相同的选项( setopt nullglob ),并可以使用 setopt failglob

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

这篇关于为什么zsh尝试扩展*而bash不扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆