Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling "?" character passed to ZSH function

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.

like image 529
penumbra Avatar asked Dec 21 '25 04:12

penumbra


1 Answers

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.

like image 179
robertklep Avatar answered Dec 23 '25 23:12

robertklep