6

I have set aliases for a few programs in the .bashrc file, and they work fine without sudo and they don't with sudo.

Is there a way to get those aliases work with sudo?

For example:

nano text.txt #alias nano='nano -icB' WORKS
sudo nano text.txt #alias does not work

NOTE: I have tried sudo -E nano text.txt, but it didn't work.

I am on Ubuntu 15.04 (Vivid Vervet).

Peter Mortensen
  • 1,029
  • 1
  • 8
  • 10
Alex Jones
  • 6,223
  • 17
  • 51
  • 83

1 Answers1

10

One way is to duplicate your aliases for the root user, too. By e. g. putting them in /root/.bashrc.

Perhaps an easier way is to simply put this in your .bashrc:

alias sudo='sudo '

The space after sudo is important. According to the bash manual:

If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.

A.P.
  • 1,416
  • 9
  • 11