cygwin: ~ != $HOME

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?

user443854

Posted 2012-04-03T18:18:47.957

Reputation: 332

1The ~ 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 – 2012-04-03T18:58:15.727

@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 – 2012-04-03T21:03:03.080

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 – 2012-04-03T23:01:07.673

@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 – 2012-04-04T12:34:58.613

Answers

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.

me_and

Posted 2012-04-03T18:18:47.957

Reputation: 2 118

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 – 2012-04-04T12:25:49.500

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

Adam.at.Epsilon

Posted 2012-04-03T18:18:47.957

Reputation: 325