From owner-freebsd-questions@FreeBSD.ORG Sat Jan 27 21:30:54 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 65BAD16A407 for ; Sat, 27 Jan 2007 21:30:54 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout4.cac.washington.edu (mxout4.cac.washington.edu [140.142.33.19]) by mx1.freebsd.org (Postfix) with ESMTP id 41DE413C46B for ; Sat, 27 Jan 2007 21:30:54 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.32.139]) by mxout4.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW06.09) with ESMTP id l0RLUrpr024939 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 27 Jan 2007 13:30:53 -0800 X-Auth-Received: from [192.168.10.41] (c-67-187-172-183.hsd1.ca.comcast.net [67.187.172.183]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW06.09) with ESMTP id l0RLUpWN005391 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 27 Jan 2007 13:30:53 -0800 Message-ID: <45BBC486.6060507@u.washington.edu> Date: Sat, 27 Jan 2007 13:30:46 -0800 From: Garrett Cooper User-Agent: Thunderbird 1.5.0.9 (X11/20070122) MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: <20070126175122.64D2616A500@hub.freebsd.org> <20070126230241.GA93074@ns.umpquanet.com> <20070126231913.GA12604@ayn.mi.celestial.com> <45BB2EEB.10204@infracaninophile.co.uk> <20070127171255.GA13120@ayn.mi.celestial.com> In-Reply-To: <20070127171255.GA13120@ayn.mi.celestial.com> X-Enigmail-Version: 0.94.1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.0.289146, Antispam-Engine: 2.5.0.283055, Antispam-Data: 2007.1.27.131934 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __LINES_OF_YELLING 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0, __USER_AGENT 0' Subject: Re: [OT] Does "~" always point to $HOME? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Jan 2007 21:30:54 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bill Campbell wrote: > On Sat, Jan 27, 2007, Matthew Seaman wrote: >> Bill Campbell wrote: > ... >>> Probably the most portable way to do this would be to use awk. A >>> simple script, homedir, might look like this: >>> >>> #!/bin/sh >>> # getting the backwhacks correct is sometimes ``interesting'' >>> homedir=`awk -F: "/^$1:/{print \\$6}" /etc/passwd` >>> >>> [ -z "$homedir" ] && { >>> echo 'empty home for ' $1 2>&1 >>> exit 1 >>> } >>> echo $homedir >>> exit 0 >> That does assume that all the user information is stored within the >> local /etc/passwd -- if you're using NIS or LDAP or anything >> like that, then you need a method that calls getpwnam(3) for you. > > A one-liner that should take care of these is: > > python -c "import os.path; print os.path.expanduser('~$username')" > > (This doesn't work with python-1.5.1 on an ancient Linux system > as os.path didn't appear until later). > > > Bill Not all systems contain python though (and many don't), so $HOME is still a better bet. Thanks though for the idea, - -Garrett -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.1 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFu8SGEnKyINQw/HARAvGpAJ4hbwv6YiF0rootWd/QTlQ1ZvweWgCgqwZ9 JCm3yiKBP2cX9dXwvIiYOz4= =Cpfv -----END PGP SIGNATURE-----