i3buntu icon indicating copy to clipboard operation
i3buntu copied to clipboard

Whoami returns root when invoked from script started with sudo

Open Yethal opened this issue 5 years ago • 2 comments

When script s started with sudo, whoami returns root instead of the username of calling user. Replace with logname for the last two lines to work correctly.

Yethal avatar Apr 22 '19 15:04 Yethal

I have tried to update the README to solve the issue. Can you test it?

mstaal avatar Aug 06 '19 17:08 mstaal

Yes, this does work. But you can simply replace $(whoami) with $(logname) to achieve the desired effect. You can test that by running following commands sudo sh -c 'echo $(whoami)' - that will return root sudo sh -c 'echo $(logname)' - that will return the correct username

Yethal avatar Aug 07 '19 06:08 Yethal