sudo doesn't support bash aliases

Matthias Klose m at klose.in-berlin.de
Sun Mar 20 15:32:35 CST 2005


On So, 2005-03-20 at 21:34 +0100, Ricardo Pérez López wrote:
> Hi again, list.
> 
> I have a question about sudo.
> 
> I come from Debian, in which I didn't use sudo, but the root account,
> for admin tasks.
> 
> I used this bash aliases, for both the "normal" user and the root user:
> 
> alias rm='rm -i'
> alias cp='cp -i'
> alias mv='mv -i'
> 
> With that way, when I type "rm file", it is translated to "rm -i file",
> asking me about if I'm sure or not erasing the file.
> 
> But "sudo rm file" doesn't takes care of the alises. "sudo rm file" is
> not translated to "sudo rm -i file".
> 
> I've tried to put the aliases in six different places:
> 
> - user's .bash_profile
> - user's .bashrc
> - root's .bash_profile
> - root's .bashrc
> - /etc/profile
> - /etc/bash.bashrc
> 
> But I have no success. sudo doesn't use bash aliases.
> 
> Is there any way to do sudo takes care of the bash aliases?

sudo calls rm, not the shell which defines the alias.

  sudo /bin/bash -c 'rm foo'

doesn't work yet, sudo doesn't read .bash_profile or /etc/profile,
because the shell is not run as a login shell. The contents of the
current .bashrc and /etc/bash.bashrc are only executed, if the shell is
interactive.

  sudo /bin/bash -i -c 'rm foo'

is one possibility, the other is to run the shell as a login shell and
place the aliases in .bash_profile.





More information about the ubuntu-devel mailing list