6

I just wanted to download a YouTube video using youtube-dl, however, zsh interprets the questionmark ? (which separates the query part of the URL) as a globbing wildcard operator (which matches any single character) and thus it aborts the command with the following error message:

$ youtube-dl https://www.youtube.com/watch?v=eDSESarTQXk
zsh: no matches found: https://www.youtube.com/watch?v=eDSESarTQXk

Is there a way to make zsh recognize URLs, perhaps using regular expression, so that it doesn’t try to glob them?

1
  • @JakeGould: I don't remember having to do that when I used oh-my-zsh, however, I can’t find the particular setting and was hoping that someone knew it off the top of their head. Perhaps they've just disabled the ? globbing wildcard operator?
    – Lenar Hoyt
    Oct 4, 2015 at 19:42

2 Answers 2

10

You could disable the NOMATCH" option of zsh:

setopt NO_NOMATCH

While the NOMATCH option is enabled (which is the default) zsh prints an error message if a pattern does not match a filename. By disabling NOMATCH, patterns that do not match a filename are kept unchanged in the argument list.

Note that the name of the option is really NOMATCH, so you have to use NO_NOMATCH to disable it, setting MATCH does not work.

Attention: This affects all globbing, not just URLs. So if you rely in any way on zsh returning errors when patterns do not match, this is not the way to go. (Sadly, unlike with NULL_GLOB there is no glob qualifier that allows enabling/disabling NOMATCH per case.)

3
  • 3
    +1 for explaining the consequences of NOMATCH, although I think your answer should have been posted to the duplicate question. And one remark: You can at least disable the NOMATCH behavior temporary with the noglob command, e.g. noglob youtube-dl url?foo=bar
    – mpy
    Oct 5, 2015 at 18:58
  • 1
    A much better solution is to automatically quote URLs: superuser.com/a/1237124/93988
    – Lenar Hoyt
    Sep 18, 2017 at 23:42
  • This worked for me. For some reason, putting quotes around the URL does not work.
    – Stephen
    Oct 28, 2021 at 23:49
2

You can put the URL in quotes, and it works.

$ youtube-dl 'https://www.youtube.com/watch?v=eDSESarTQXk'
[youtube] eDSESarTQXk: Downloading webpage
[youtube] eDSESarTQXk: Downloading video info webpage
[youtube] eDSESarTQXk: Extracting video information
...
1

Not the answer you're looking for? Browse other questions tagged .