2

Let's say I want to create an alias called ss for the command sudo -s. But ss is already an existing command, so I want to create another alias called sst for the command ss.

If using just the normal command names, this is not possible, since aliases:

  1. Are not set in a way that respects the order, and
  2. Reference other aliases, instead of only referencing commands

So if I try the following:

alias sst='ss'
alias ss='sudo -s'

Running the command sst results in running sudo -s, which is not my intention.

How can this be done?

Artur Meinild
  • 31,035

1 Answers1

2

For the above to work, you need to reference the absolute path of the command you want to run.

The can be done with the following:

alias sst='/usr/bin/ss'
alias ss='sudo -s

However, one can't always be sure ss is at that location, so a more solid approach would be:

alias sst='$(which ss)'
alias ss='sudo -s

Now the above works as expected, where ss runs sudo -s and sst runs the command ss.

Artur Meinild
  • 31,035