delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/09/28/13:36:59

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Dave Korn" <dk AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
Subject: RE: "which" command does not expand "~" in path (base-files update needed)
Date: Tue, 28 Sep 2004 18:34:50 +0100
MIME-Version: 1.0
In-Reply-To: <Pine.GSO.4.61.0409281308460.4220@slinky.cs.nyu.edu>
Message-ID: <NUTMEGCtgx8VUkRacUt0000013f@NUTMEG.CAM.ARTIMI.COM>
X-OriginalArrivalTime: 28 Sep 2004 17:36:35.0939 (UTC) FILETIME=[B3D0DB30:01C4A581]

> -----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 AT 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 AT mace ~> export FOO=~/bin:"${PATH}"
dk AT 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 AT 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 AT 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 AT mace ~> export FOO=~/bin:${PATH}
dk AT 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 AT 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 AT 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 AT 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 AT 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 AT 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 AT 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 AT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019