This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: "which" command does not expand "~" in path

From: Sven Köhler
Subject: Re: "which" command does not expand "~" in path
Date: Sat, 25 Sep 2004 20:32:31 +0200
Message-ID: <cj4diq$1du$>

Set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then

Hmm, i'm not 100% percent sure, but is this supposed to work in general? I don't think that all programs that use the PATH varible are supposed to interpret ~ correctly.

I don't know for certain (I am no expert), BUT I briefly examined source code of both GNU "which" and cygwin "which" and the GNU version specifically checks for "~" while the cygwin version does not. The cygwin version essentially passes the partial PATH directly to a stat() function call. I do not know if stat() is expected to interpret ~ as $HOME.

Instead, the shell usually substitutes ~ or ~user.
Look at this the output of these commands:
        echo ~
        echo "~"

I'm fairly certain the shell is not expected to perform tilde expansion if the tilde is quoted, so the difference between these two is expected.

I would suggest to use
or even
  PATH="$(echo -n ~)/bin:$PATH"
instead of your line.

The "PATH=.." line I quoted is from the _cygwin default .bash_profile_, so if what you suggest is true, either way something in cygwin needs to be modified (and yes, substituting $HOME for ~ does fix it, but that doesn't stop someone manually putting ~ in their path). The which command on linux works as expected, whether the path contains ~ or not.
I'm sure Corinna will know the correct behaviour - she's also the maintainer of "which" ;-)

Regards, Errol

btw, I am using a fully updated cygwin with snapshot 20040924

btw2, if anyone knows how to get Eudora to let me reply to the digest and have it thread properly in the archives, please let me know..

-- Unsubscribe info: Problem reports: Documentation: FAQ:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]