4

I have a script that I call with sudo -- sudo script, and I want to be able to see the username of the user running the script (not root).

Sticking whoami or id -un inside the script just gives me root.

10

sudo creates an environment variable called SUDO_USER. You can use it in your script like so:

echo $SUDO_USER

2

You can look at the SUDO_USER, SUDO_UID or SUDO_GID environmental variables to find this information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.