LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Sudo and aliases (https://www.linuxquestions.org/questions/linux-general-1/sudo-and-aliases-890408/)

rgdacosta 07-07-2011 06:19 AM

Sudo and aliases
 
Hello

vi is aliased to vim

Code:

[ricardo@athena /]$ type vi
vi is aliased to `vim'

When I run sudo vi, it starts vi and ignores the alias - how do I fix this?

Code:

[ricardo@athena /]$ ps a | grep vi
15515 pts/0    S+    0:00 sudo vi /etc/sysconfig/selinux
15516 pts/0    S+    0:00 vi /etc/sysconfig/selinux


TobiSGD 07-07-2011 06:22 AM

Did you have aliased vi to vim for the root user also?

rgdacosta 07-07-2011 06:54 AM

Yup - it's in ~/.bashrc

Code:

[root@athena ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@athena ~]# type vi
vi is aliased to `vim'


sundialsvcs 07-07-2011 07:46 AM

As far as I know, sudo ignores aliases ... for what should be obvious reasons. Think about it like a University freshman would have done in the 1970's...

(Heh... after you finish that delicious bong ...)

rgdacosta 07-07-2011 08:14 AM

Solution!

in ~/.bashrc

Code:

alias sudo="sudo "
Make sure that a blank space exists after the second sudo and it will honour the aliases.


All times are GMT -5. The time now is 10:09 AM.