Is it possible to have cygwin ignore the Windows HOME environment variable?

As part of installing EGit, I had to set a HOME environment variable in Windows. This caused a problem whereby cygwin considers the HOME environment variable in Windows more important than the value in /etc/passwd. As a result, cygwin thinks my HOME directory in cygwin has moved from its previous location to my Windows user profile folder. I'd rather keep my cygwin files separate as my user profile folder is cluttered enough already but it doesn't seem to be possible to do so.

Is there any way to have cygwin use the value from /etc/passwd instead of the HOME enviroment variable?


Solution 1:

Edit /etc/profile and change the lines

# Set the user id
USER="$(id -un)"

to

# Set the user id
USER="$(id -un)"

# Set user home dir
HOME=$(eval echo "~$USER")

This forces Cygwin always to use the value from /etc/passwd. This is better than using Cygwin.bat because this applies to all login shells, no matter how they're spawned.

Solution 2:

The cygwin.bat file generally used to start the Cygwin shell can be modified to do whatever you need with HOME. You could try:

set HOME=

This should, based on documentation and experience, actually UNset %HOME% so that cygwin does not see it. As cygwin will default to setting up $HOME as the value in /etc/passwd (if HOME is not set in the parent process from which it inherits the environment), you should then get the result you want.

Notice please that I am stating that

set HOME=

actually removes HOME from the set env variables; not, as one might expect, the alternative result of setting HOME to the null string (but leaving it hanging around in the environment).