Galladite
Galladite

Reputation: 137

Running a script as another user while knowing who ran the script

In Linux, need to write a shell script which can be ran as other users (via doas permissions for this one script), but I need to know in the script who ran it originally. How would I go about doing this?

Upvotes: 0

Views: 49

Answers (1)

Barmar
Barmar

Reputation: 781096

From the man page

By default, a new environment is created. The variables HOME, LOGNAME, PATH, SHELL, and USER and the umask(2) are set to values appropriate for the target user. DOAS_USER is set to the name of the user executing doas.

So use $DOAS_USER to get the original username.

Upvotes: 1

Related Questions