What's the difference between the `USER` and `USERNAME` environment variables?
On windows:
ENV['username']
will output the current username.On linux: If the script is run through
sudo
,"USER"
will be thesudo
-ed-to user (usuallyroot
) 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.