I just came to know about the alias option and I have this code which would download any youtube vid in the highest quality. But the problem is I have to enter the url of the youtube vid. Is there any way to create alias for it. I tried alias youtube="youtube-dl -f best 'link'" but it takes link as the url since I've not given a variable. Is there anyway to get an input and save it in the variable link.

2 Answers 2


aliases are not set by terminal or iTerm they are a part of your shell.

By default in BigSur it is zsh, for most other versions before the default shell was bash

aliases do not take a parameter they just do a text replacement of the alias by the text to the right of the = If you need to do things with parameters then look at functions in the shell manuals.

As to your case an alias will work as the alias is expanded and then the rest of the command line is passed to it.

A simple example is to get a long list of files

alias ll='ls -l'

Call this by ll ~

and you get the same result as ls -l ~

I think in your case you just need

alias youtube='youtube-dl -f best '

Then type (where link is the URL you want)

youtube link

Based on what you described, I can suggest two more options:

  1. alias youtube="youtube-dl -f best '$1'" ($1 - is the first argument following your command, if you have to use single quotes)
  2. youtube() { echo -n "YouTube link: " ; read _url ; youtube-dl -f best '$_url' ; } (multi command function with a prompt line)

Or if you don't have to use quotes or anything complicated, then what mmmmmm posted will be your solution.

You must log in to answer this question.

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