3

I'm having problem with setting up simple function in ZSH.

I want to make function which downloads only mp3 file from youtube.

I used youtube-dl and i want to make simple function to make that easy for me

ytmp3(){
  youtube-dl -x --audio-format mp3 "$@"}

So when i try

ytmp3 https://www.youtube.com/watch?v=_DiEbmg3lU8

i get

zsh: no matches found: https://www.youtube.com/watch?v=_DiEbmg3lU8

but if i try

ytmp3 "https://www.youtube.com/watch?v=_DiEbmg3lU8"

it works. I figured out that program runs (but wont download anything) if i remove all charachers after ? including it. So i guess that this is some sort of special character for zsh.

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
penumbra
  • 125
  • 1
  • 8

2 Answers2

3

By default, the ZSH will try to "glob" patterns that you use on command lines (it will try to match the pattern to file names). If it can't make a match, you get the error you're getting ("no matches found").

You can disable this behaviour by disabling the nomatch option:

unsetopt nomatch

The manual page describes this option as follows (it describes what happens when the option is enabled):

If a pattern for filename generation has no matches, print an error, instead of leaving it unchanged in the argument list.

Try again with the option disabled:

$ unsetopt nomatch
$ ytmp3 https://www.youtube.com/watch?v=_DiEbmg3lU8

If you want to permanently disable the option, you can add the disable command to your ~/.zshrc file.

robertklep
  • 198,204
  • 35
  • 394
  • 381
1

The question mark is part of ZSH's pattern matching, similarly to *. It means "Any character".

For instance, ls c?nfig will list both "config" and "cinfig", provided they exist.

So, yes, your problem is simply that zsh is trying to interpret the ? in the URL as a pattern to match to files, failing to find any, and crapping out. Escape the ? with a \ or put quotes around it, like you did, to fix it.

Chris Kitching
  • 2,559
  • 23
  • 37
  • I found a kind of way around I made a script that open bash shell interpreter and i just parse whole link into that. It's kind of linked bash function. Thanks for the answer! (i cant upvote my rep is to low) – penumbra Apr 16 '16 at 18:49