delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/09/26/21:29:32

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
Date: Sun, 26 Sep 2004 21:29:26 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: =?ISO-8859-1?Q?Sven_K=F6hler?= <skoehler AT upb DOT de>
cc: cygwin AT cygwin DOT com
Subject: Re: "which" command does not expand "~" in path
In-Reply-To: <cj7ml6$f5s$1@sea.gmane.org>
Message-ID: <Pine.GSO.4.61.0409262122350.630@slinky.cs.nyu.edu>
References: <1094385246 DOT 5803 DOT ezmlm AT cygwin DOT com> <6 DOT 1 DOT 2 DOT 0 DOT 1 DOT 20040926005459 DOT 02810cb0 AT mail DOT ros DOT com DOT au> <cj4diq$1du$1 AT sea DOT gmane DOT org> <cj4np8$b17$1 AT sea DOT gmane DOT org> <cj6vur$cqc$1 AT sea DOT gmane DOT org> <Pine DOT GSO DOT 4 DOT 61 DOT 0409262003520 DOT 630 AT slinky DOT cs DOT nyu DOT edu> <cj7ml6$f5s$1 AT sea DOT gmane DOT org>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 2.39

---559023410-126398554-1096248566=:630
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8BIT

On Mon, 27 Sep 2004, Sven Köhler wrote:

> > > But is there any command that give's me the home for a given username?
> >
> > bash -c "echo ~username"
>
> Oh well, beside bash (and any other big programm called shell)
>
> > Or you could write one using the getpwnam() call (better yet, the
> > reentrant versions, getpwnam_r()), and submit it to, say, cygutils (since
> > sh-utils is no longer being actively developed).
>
> 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
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT 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

---559023410-126398554-1096248566=:630
Content-Type: text/plain; charset=us-ascii

--
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/
---559023410-126398554-1096248566=:630--

- Raw text -


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