TIL: EXTENDED_GLOB & noglob in Zsh
When I try to download a file using wget
or make a curl
request, and the URL contains query parameters (e.g., curl https://google.com?q=zsh
), zsh gets mad at me if I forget to wrap the URL in quotes. It throws an error that looks like this:
zsh: no matches found: https://google.com?q=zsh
This is because the ?
is a glob operator in zsh (ref. EXTENDED_GLOB
). Although useful in other situations, it definitely does not help here. When looking for a possible solution to this problem, I came across noglob
.
noglob
lets you disable glob matching for a given command. Modifying the above example to use noglob
, we get
noglob curl https://google.com?q=zsh
Running curl
with noglob
fixes the issue. To avoid having to type noglob
each time, I aliased curl
& wget
to use noglob
in my ~/.zshrc
. While looking for more information about noglob
, I came across this blog post which pointed out that noglob
can also be used for running Rake tasks that accept parameters (e.g., rake new_post["hello world"]
).