ZSH's extended glob breaking commands

After running a command like $ rake new_post["hello world"], you may have seen an error like the following:

zsh: no matches found: new_post[...]

The issue is that you have ZSH’s extended glob turned on. If you look in your ZSH config you’ll see the following line:

setopt extended_glob

This options enables globbing patterns in ZSH. And in the previous example, the ["hello world"] in $ rake new_post["hello world"] acts like a regexp rather than a literal string. For more info, this blog introduces ZSH globbing and expansion, and this page comprehensively documents globbing and expansion.

You have a couple ways to fix this problem and I prefer the first way:

  • Disable globbing by aliasing the command, for example:
    alias rake="noglob rake"
  • Quote the command’s arguments:
    rake 'new_post["hello world"]'
    Till next time, keep calm and ZSH on.