I have a huge alias file sourced by ~/.bashrc or ~/.zshrc which contains both simple aliases and more functions for more complex stuff:
# example aliases
alias "sudo=sudo "
alias "testalias=echo 'Aliases work as expected'"
# example function
testfunction(){
echo "Function $1 works as expected"
}
This is what happens if I run these commands with or without sudo:
> testalias
Aliases work as expected
> testfunction "test"
Function test works as expected
> sudo testalias
Aliases work as expected
> sudo testfunction "test"
sudo: testfunction: command not found
I've seen no difference either with
export -f testfunction && sudo -E testfunction "test"alias "testfunction-alias=testfunction" && sudo -E testfunction-alias "test"
How can I call functions from sudo as I am already doing with aliases?
Possibly without exporting/creating an alias for each one of them, as they are numerous.