0

When I start cygwin, my ~ dir is the same as $HOME. After some time, ~ dir changs, while $HOME stays the same. I am puzzled by this, not sure where to look. Maybe someone experienced this, or has some clue what's going on? When I start:

winuser@mybox ~
$ echo $HOME
/cygdrive/c/cyguser

winuser@mybox ~
$ echo ~
/cygdrive/c/cyguser

Later, ~ changes to /cygdrive/c/winuser, which is non-existent. When I restart cygwin, everything is back to normal. What could be causing this?

migrated from stackoverflow.com Apr 3 '12 at 18:50

This question came from our site for professional and enthusiast programmers.

  • 1
    The ~ character is expanded to the value of $HOME by the bash shell. The only time this won't happen is if $HOME is not set; then it's expanded to the home directory of the current user, but that's not consistent with what you're describing. Please show us (copy-and-paste) the output of echo \~ = ~, HOME = $HOME, USER = $USER, \~winuser = ~winuser. And normally your home directory should be /home/winuser; why and how did you change it? – Keith Thompson Apr 3 '12 at 18:58
  • @Keith I set HOME under user section of environment variables dialog. It is set to C:\cyguser. I am waiting for the problem to reoccur. Currently: ~ = /cygdrive/c/cyguser , HOME = /cygdrive/c/cyguser, USER = winuser, ~winuser = /home/winuser. Thanks for looking into this. – user443854 Apr 3 '12 at 21:03
  • Whatever is causing this behavior (~ and $HOME should be the same), I think you'll be better off using the default settings, with your Cygwin home directory set to /home/username. If you want your Cygwin home directory to be directly under C:` for some reason, you can make /home/username. The inconsistency between cyguser` and winuser is also confusing. – Keith Thompson Apr 3 '12 at 23:01
  • @Keith the inconsistency is for two reasons. First, I had other things, such as .emacs, at that location before cygwin. And second, my windows user name is assigned by admin, it is too long to type and different from all other computers I use. – user443854 Apr 4 '12 at 12:34
2

Your/etc/passwd file is wrong; it'll be listing your home directory as /cygdrive/c/winuser. Fix it by editing that file and correcting the field.

I've had similar problems; Cygwin bash doesn't read your home directory from the passwd file at start up, so ~ is correct, but certain things (I never managed to work out what, exactly) will cause it to reload and reset from that file, picking up the wrong value. I think it's a side-effect of a slightly dodgy package update, but I'm not sure.

  • Yes, my /etc/passwd lists my home dir as /home/winuser. I changed it to /cygdrive/c/cyguser. Thank you very much. This ~ changing on me at random was very annoying. Thx! – user443854 Apr 4 '12 at 12:25
1

If before installing cygwin you create a HOME variable as a Windows environment variable, you can point this to wherever you want in your Windows PC (directory must exist).

Then when you install cygwin, it takes this into account and creates a correct /etc/passwd for you.

I use the subst to create a drive alias for my Windows "My Documents" directory:

H:\ => C:\Users\WINUSERNAME\Documents

then in Windows I set

HOME=H:\

This then becomes

/cygdrive/h

in Cygwin, simple and with no spaces etc which can be awkward.

The advantage is then that my home directory in cygwin is identical to "My Documents".

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.