Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" To: Subject: RE: "which" command does not expand "~" in path Date: Mon, 27 Sep 2004 19:27:44 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" In-Reply-To: Message-ID: X-OriginalArrivalTime: 27 Sep 2004 18:27:44.0923 (UTC) FILETIME=[AEA8E6B0:01C4A4BF] Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id i8RISFaW016340 > -----Original Message----- > From: Igor Pechtchanski > Sent: 27 September 2004 18:50 > 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" > 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 That's not a correction, that's an improvement..... ...well, if you assume that multiple matches from the first version was a feature, not a bug.... 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/