I have dyslexia so I use fish as my shell since it's great with prediction, correction and aliasing. I'm trying to figure out how to make an alias with a variable inside followed by the rest of the alias.

Example: Right now I have alias ppa="sudo add-apt-repository". I can just type ppa then copy the repo's ppa:foo-bar/ppa afterward and end up with sudo apt-add-repository ppa:foo-bar/ppa

This is convenient enough, so if this next part would be too difficult or plain ol' impossible to do, no worries.

I'd like to amend this alias to ppa="sudo add-apt-repository" ; upd(where upd is also aliased asupd="sudo apt update"`). Is there a way I can do this? In case I'm not being clear enough, here's what I'd like to do with the cli in this case:

alias with variable:
$ ppa [variable]

decoded alias with variable:
$ sudo sudo add-apt-repository [variable] ; upd

Example as above: alias with variable:
$ ppa ppa:foo-bar/ppa

decoded alias with variable:
$ sudo sudo add-apt-repository ppa:foo-bar/ppa ; upd

Is there a way to do this? Again, if not or if its way too complicate for what it's worth, no problem.

Thanks a lot! I appreciate it!

〜 Ev

PS -- If anyone would like me to help them make their own aliases for commands they enter all the time and wish to do so using fish, feel free to ask. I'd be glad to help!


2 Answers 2


No, you can't do this with a fish alias. But fish functions are much better:

function upd
    sudo apt update
funcsave upd

function ppa
    sudo add-apt-repository $argv
funcsave ppa

Copy and paste this into your terminal and you should be good to go.

Keep in mind that

alias foo=bar

is simply a shortcut for

function foo; bar $argv; end

I would create a script for that and make the alias call the script. Something like this (untested): add_ppa_and_update.sh

# Take first argument and use it to add the repository
add-apt-repository $1
# Update
apt update

Now give the script run permissions sudo chmod 755 add_ppa_and_update.sh and create an alias that calls the script with sudo sudo add_ppa_and_update.sh [variable].

  • 2
    c'mon. This is like answering a python question with a perl answer. Aug 5, 2016 at 19:38

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.