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 (base-files update needed)


> -----Original Message-----
> From: cygwin-owner On Behalf Of Igor Pechtchanski
> Sent: 28 September 2004 18:15

> > You can use ~ here.  Just don't quote it.  It shouldn't be quoted.
> >
> > export PATH=~/bin:"${PATH}"
> 
> I'm sorry, but this isn't true, even for bash.  It still 
> leaves the "~" in
> the PATH, which confuses "which" (although "type", being a 
> bash builtin, recognizes and expands it).

  Why isn't it expanded by bash's tilde substitution at the time the 'export'
command line is parsed then?  That's sooo wrong.  Oh wow.  Guess what: it depends
whether the *other* part of the assignment is quoted or not:

dk@mace ~> echo ${PATH}
/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32:/win/c/WINDO
WS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> export FOO=~/bin:"${PATH}"
dk@mace ~> echo "${FOO}"
~/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32:/win/c
/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> echo ${FOO}
~/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32:/win/c
/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> echo $FOO
~/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32:/win/c
/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> export FOO=~/bin:${PATH}
dk@mace ~> echo "${FOO}"
/home/dk/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32
:/win/c/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> echo ${FOO}
/home/dk/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32
:/win/c/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> echo $FOO
/home/dk/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32
:/win/c/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~>

<  The "~" is not expanded when used in a
> variable assignment (whether quoted or unquoted), even if 
> 'echo' expands it.  

  I disagree.  The ~ is not expanded when quotation is used, even if the ~ itself
is not quoted.  The expansion seems not to be being performed by echo.


>Oh, and your suggestion definitely won't work for sh, 
> which also uses
> /etc/profile.  IMO, any shell-specific code in /etc/profile 
> should go into
> the shell-specific section of /etc/profile, and the rest of 
> it should be
> Bourne shell compatible.

  Given that we don't care about the home dir of any but the currently-logged in
user, there's no need to go to such lengths of grepping /etc/passwd: wouldn't the
most generic, cross platform thing to be to take advantage of the behaviour of cd
?

dk@mace ~> echo "${FOO}"
/home/dk/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32
:/win/c/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> echo ${FOO}
/home/dk/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32
:/win/c/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~> echo $FOO
/home/dk/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/win/c/WINDOWS/system32
:/win/c/WINDOWS:/win/c/WINDOWS/System32/Wbem
dk@mace ~>

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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