There are two things I want: 1) I want that if I keep using sudo
often that it never asks me for my password by updating my cached credentials every time I type sudo
, 2) That I can use (certain) aliases while using sudo.
In order to update ones credentials one has to execute sudo -v
(without command).
For example, I do not have a /usr/bin/vi
. I do have a /usr/bin/nvim
. I have an alias:
alias vi='/usr/bin/nvim'
So, if I type as non-root:
sudo vi /etc/fstab
Then I want that is executed:
sudo -v
sudo /usr/bin/nvim /etc/fstab
I tried to achieve this by creating the bash function:
function sudo()
{
command sudo -v
command sudo "$@"
}
However, this results in the error:
sudo: vi: command not found
In other words, the alias vi
is not expanded from the "$@"
inside the sudo
function.
How can I fix this?
alias sudo='sudo -v; sudo '
sudo: vi: command not found