Risoluzione dell'errore "zsh: no matches found" durante l'esecuzione di un task rake

macOS ora include zsh come shell predefinita, il che significa che questo problema si presenta abbastanza regolarmente.

In zsh:

% bin/rake plugin:spec[discourse-solved]
zsh: no matches found: plugin:spec[discourse-solved]
Perché succede questo?

Questo accade perché le parentesi quadre vengono interpretate come un pattern glob. In bash, il glob non riesce a trovare una corrispondenza, ma il comando viene comunque eseguito e funziona. Al contrario, zsh genera un errore e non esegue rake.

Per illustrare, in bash:

○ → echo bin/rake plugin:spec[discourse-solved]
bin/rake plugin:spec[discourse-solved]

○ → touch plugin:specd

○ → echo bin/rake plugin:spec[discourse-solved]
bin/rake plugin:specd

Puoi replicare il comportamento di zsh abilitando l’opzione failglob in bash:

○ → echo bin/rake plugin:spec[discourse-solved]
bin/rake plugin:spec[discourse-solved]

○ → shopt -s failglob

○ → echo bin/rake plugin:spec[discourse-solved]
bash: no match: plugin:spec[discourse-solved]

(grazie a @j.jaffeux e @pmusaraj per avermi indicato la direzione giusta, e a @supermathie per gli esempi bash :heart_eyes:)

Per farlo funzionare come previsto, è necessario racchiudere l’intero argomento di rake tra virgolette

% bin/rake "plugin:spec[discourse-solved]"
22 Mi Piace

Ouch. That sounds like it’s going to cause a bunch of pain to people who are not likely to have any idea how to figure out the problem. Hopefully they’ll find this topic.

3 Mi Piace

It’s mostly fine - scripts can just specify bash to avoid any pain.

2 Mi Piace

True enough. I guess that’s why all of my bash scripts start with #!/usr/bin/env bash even though I don’t expect them ever to run on a Mac :wink:

3 Mi Piace

Or, you could add an alias to your ZSH config. :slight_smile:
That works on Linux, so it will probably work on macOS as well.

alias rake='noglob rake'
7 Mi Piace