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?

Giacomo1968
  • 58,727

2 Answers2

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.)

Adaephon
  • 6,094
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
...