6

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?

6

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.

3
  • Alternatives: HOME=$(awk -F: "/^$USER:/ { print \$6 }" /etc/passwd) or HOME=$(eval echo "~$USER") Jun 4 '13 at 22:01
  • Your cat is unnecessary; you can change cat /etc/passwd | fgrep "$USER" to fgrep "$USER" /etc/passwd. Also, your command can misbehave if your user name happens to appear elsewhere in /etc/passwd, perhaps as part of another user name or of some other field. Jun 4 '13 at 22:03
  • Answer updated to use the HOME=$(eval echo "~$USER") method. That's really cool, thanks. Jun 4 '13 at 23:32
3

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).

1

Here are a couple of things you can try:

  1. Edit cygwin.bat and set HOME= to whatever dir you want.

  2. Edit /etc/profile (C:\cygwin\etc\profile) and change cd "${HOME}" to whatever dir you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.