I am trying to use the solution of using sudo on my existing aliases as covered in many existing answers already and i am so confused as to why it is not working
alias sudo='sudo '
I keep all my aliases in .bash_aliases. Inside .bash_aliases I have this
function _test {
echo 'test!'
}
alias test='_test'
I reload the .bashrc each time; source .bashrc but when I run sudo test I always get
sudo: _test: command not found
The only strange thing that happens is that I get the following on reload and not on a new terminal
dircolors: /home/MYHOME/.dircolors: No such file or directory
but i feel this is a red herring.
sudoruns in a clean-ish environment. You can't execute user shell functions like this. The only reason the alias works is because it's expanded before sudo is called.alias sudo='sudo 'doesn't do anything interesting. Nor does your function alias; you could simply definetest() { echo 'test!'; }in the first place, no alias needed.sudousesexecve()to directly invoke the executable that is to be its child process; that's an OS-level syscall. aliases are just an interactive shell construct; they don't work at any other layer, including noninteractive shell scripts (and it's bad form to rely on them at all; while whether they can be exported across a privilege boundary depends on the details of howsudois configured and it's much better from a security perspective if they're disallowed, exported functions can sometimes work throughsudo, whereas aliases never will).sudoa function, an alias or a builtin, only an executable file that is on your disk. The indirect way of doing this is throughsudo bash -c .... All this looks like an XY problem to me, though