Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • After running 'sudo su -' the environment variables aren't available, but logname and who am i work. Commented Mar 3, 2015 at 1:47
  • You're right, it's not possible to rely on environment variable. Commented Mar 5, 2015 at 10:09
  • Found on some host that SUDO_USER can't be overwritten: sudo: sorry, you are not allowed to set the following environment variables: SUDO_USER So it may still be safe, should still verify this. Commented Feb 17, 2016 at 8:31
  • It's because my command is set as "NOPASSWD", so it depends on your sudoers configuration via "NOSETENV". Commented Feb 17, 2016 at 8:49
  • It appears that neither of these commands work in situations where there's no login, which at least includes WSL and docker. Commented Oct 18, 2024 at 1:17

lang-bash