Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

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.

share|improve this answer
    
Alternatives: HOME=$(awk -F: "/^$USER:/ { print \$6 }" /etc/passwd) or HOME=$(eval echo "~$USER") –  Keith Thompson 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. –  Keith Thompson Jun 4 '13 at 22:03
    
Answer updated to use the HOME=$(eval echo "~$USER") method. That's really cool, thanks. –  Pun Jun 4 '13 at 23:32
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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