Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between the `USER` and `USERNAME` environment variables?

I'm not entirely sure which one to use.

like image 463
RyanScottLewis Avatar asked Dec 13 '10 19:12

RyanScottLewis


1 Answers

  • On windows: ENV['username'] will output the current username.

  • On linux: If the script is run through sudo, "USER" will be the sudo-ed-to user (usually root) and "USERNAME" will be the user who ran sudo.

  • On Mac : only USER exists (on MacOS 10.15. To be confirmed on previous versions)

Here's a list of XP Environment variables: http://vlaurie.com/computers2/Articles/environment.htm

And here's a list of Vista/7 Environment variables, you'll notice they are slightly different: http://vlaurie.com/computers2/Articles/environment-variables-windows-vista-7.htm

Edit: The safest approach would be to write a small function that determines what system you are on (I gather from your comment above you're wanting a Write-Once, Run-Anywhere app) and sets the appropriate values based upon that.

like image 158
Caladain Avatar answered Oct 04 '22 23:10

Caladain