Execute a shell script in current shell with sudo permission
I'm not sure if this breaks any rules but
sudo bash script.sh
seems to work for me.
What you are trying to do is impossible; your current shell is running under your regular user ID (i.e. without root the access sudo
would give you), and there is no way to grant it root access. What sudo
does is create a new *sub*process that runs as root. The subprocess could be just a regular program (e.g. sudo cp ...
runs the cp
program in a root process) or it could be a root subshell, but it cannot be the current shell.
(It's actually even more impossible than that, because the sudo
command itself is executed as a subprocess of the current shell -- meaning that in a sense it's already too late for it to do anything in the "current shell", because that's not where it executes.)