This is the mail archive of the
cygwin
mailing list for the Cygwin project.
RE: "which" command does not expand "~" in path
- From: Igor Pechtchanski <pechtcha at cs dot nyu dot edu>
- To: Dave Korn <dk at artimi dot com>
- Cc: cygwin at cygwin dot com
- Date: Mon, 27 Sep 2004 13:49:35 -0400 (EDT)
- Subject: RE: "which" command does not expand "~" in path
- References: <NUTMEGkxOjmfCHJr1Wt0000010a@NUTMEG.CAM.ARTIMI.COM>
- Reply-to: cygwin at cygwin dot com
On Mon, 27 Sep 2004, Dave Korn wrote:
> > -----Original Message-----
> > From: cygwin-owner On Behalf Of Hannu E K Nevalainen
> > Sent: 27 September 2004 18:24
>
> > you wrote:
> >
> > > On Mon, 27 Sep 2004, Sven Köhler wrote:
>
> > >> I just wondered how to write a "correct" shell-script that
> > runs with
> > >> /bin/sh, and it seems there is no way "shell-script"-way to figure
> > >> out a user's homedir.
> > >
> > > You could try
> > >
> > > awk -F: "/^username:/"'{print $6}' < /etc/passwd
> > >
> > > (the pattern is in double quotes so that variable substitution can
> > > occur, e.g., you could change "username" to "$1" in a shell script).
> > > Igor --
> >
> > $ u="Hannu";sed -nre "s/^$u.*:(.*):.*$/\1/p" </etc/passwd
This works only because "/" is not a valid variable name. :-p
> > I bet there are some more other ways to do it... ;-P
>
> My first thought was
>
> grep "username" /etc/passwd | cut -d ':' -f 6
Correction for the archives:
grep "^username:" /etc/passwd | cut -d ':' -f 6
Igor
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing." -- Dr. Jubal Harshaw
--
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/