3

I have an alias for youtube_dl which adds some arguments in my .bashrc file. I want to run this in a separate terminal similar to how it is done here. The problem is that this takes a string as input.

my current alias:

alias youtube-dl="youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"

how I want the new alias to look like:

alias youtube-dl='gnome-terminal -e "youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"'

The problem is, however, that now the '-strings are interpreted as two separate strings. In addition, I am now unable to add the url as an argument. How do I circumvent this?

1 Answer 1

6

You could mess around with quotes and escaping, but I prefer to look for ways to reduce the quoting levels. For example, you could use gnome-terminal -x instead:

-e, --command=STRING
         Execute the argument to this option inside the terminal.

-x, --execute
         Execute  the  remainder  of  the  command  line  inside   the
         terminal.

So,

gnome-terminal -e "youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'"

Becomes:

gnome-terminal -x youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s'

Shaving off one layer of quotes. And the alias would be:

alias youtube-dl='gnome-terminal -x youtube-dl -ci --restrict-filenames -o "%(title)s.%(ext)s"'

Or you could use a function:

youtube-dl()
{
    gnome-terminal -x youtube-dl -ci --restrict-filenames -o '%(title)s.%(ext)s' "$@"
}
2
  • +1 for the function. That was my first thought, using a function.
    – Parto
    Apr 7, 2016 at 11:26
  • Should take advantage of export -f youtube-dl after the function definition. Apr 7, 2016 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.