Search code examples
shellzshglob

different shell behaviors of unmatched glob in zsh and bash


When I use a miniconda environment, I want to use this command to install a python package.

pip install recommenders[examples]

In zsh, it returns a error.

zsh: no matches found: recommenders[example]

In bash, it is successful and installs the package.

Someone told me that zsh treats unmatched glob as an error, but bash treats it as a literal text.

How should I change .zshrc in order to make zsh behaves like bash at this point, aka treats unmatched glob in "[]" as a literal text?

Thanks for any suggestion in advance.

(Besides, I am a beginner to zsh. I even don't know how to google it. What is the keyword of this problem? thx)


Solution

  • Use setopt NONOMATCH to leave an unmatched glob as literal text.

    Similarly, use setopt NULL_GLOB to treat an unmatched glob as if it hadn't been used at all.

    Some examples:

    % print recommenders[examples]
    zsh: no matches found: recommenders[example]
    % setopt NONOMATCH
    % print recommenders[examples]
    recommenders[examples]
    % print recommenders[examples]
    
    %
    

    Both options are documented under man zshoptions. (Use man zsh to see what man pages are available, or man zshall to see all of them at once.)