2
function y-dl ($URL) {
cd ~/Music/
youtube-dl -f bestaudio --prefer-ffmpeg --extract-audio --audio-format mp3 $URL > /dev/null 2>&1
}

I'm trying to write a bash function for my bash profile that downloads YouTube Audio without any verbosity in stderr or stdout but I get the following compilation error:

-bash: /Users/mu/.bash_profile: line 11: syntax error near unexpected token `$URL'
-bash: /Users/mu/.bash_profile: line 11: `function y-dl ($URL) {'

I'm trying a variant of the top answer from Passing parameters to a Bash function but I can't get it to work.

O.rka
  • 29,847
  • 68
  • 194
  • 309

1 Answers1

2

The correct and modern way :

y-dl() {
    cd ~/Music/
    youtube-dl -f bestaudio --prefer-ffmpeg --extract-audio --audio-format mp3 "$1" &>/dev/null
}

function construction never takes arguments in a signature style Ex: func(foo, bar) it's shell

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223