I have a use case where I want to sudo su - user1 to some user and then run script and in the script I want to fetch SUDO_USER. However the SUDO_* environment variables do not get set when I use sudo su - user1 instead of sudo su app.
sudo su user1
[sudo] password for rbhanot:
$ env | grep -i sudo
SUDO_COMMAND=/bin/su user1
SUDO_GID=4361
SUDO_UID=4361
SUDO_USER=rbhanot
If I invoke su with login shell these variables are not set
sudo su - user1
$ env|grep -i sudo
$
It works if I use a slightly different command with sudo -i
sudo -i -u user1
$ env|grep -i sudo
SUDO_COMMAND=/bin/ksh
SUDO_GID=4361
SUDO_UID=4361
SUDO_USER=rbhanot
So why does these SUDO_* variables do not get with su - user1 specifically.