From owner-freebsd-questions@FreeBSD.ORG Sat Jan 27 17:08:53 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 783A016A403 for ; Sat, 27 Jan 2007 17:08:53 +0000 (UTC) (envelope-from bill@ayn.mi.celestial.com) Received: from ayn.mi.celestial.com (hayek.celestial.com [192.136.111.12]) by mx1.freebsd.org (Postfix) with ESMTP id 3880413C46C for ; Sat, 27 Jan 2007 17:08:52 +0000 (UTC) (envelope-from bill@ayn.mi.celestial.com) Received: from localhost (localhost [127.0.0.1]) by ayn.mi.celestial.com (Postfix) with ESMTP id 0DE2268614142; Sat, 27 Jan 2007 09:12:56 -0800 (PST) X-Virus-Scanned: amavisd-new at mi.celestial.com Received: from ayn.mi.celestial.com ([127.0.0.1]) by localhost (ayn.mi.celestial.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id yjhusRXzGbgw; Sat, 27 Jan 2007 09:12:55 -0800 (PST) Received: by ayn.mi.celestial.com (Postfix, from userid 203) id E3C9A6860B90A; Sat, 27 Jan 2007 09:12:55 -0800 (PST) Date: Sat, 27 Jan 2007 09:12:55 -0800 From: Bill Campbell To: freebsd-questions@freebsd.org, Bill Campbell Message-ID: <20070127171255.GA13120@ayn.mi.celestial.com> Mail-Followup-To: freebsd-questions@freebsd.org, Bill Campbell References: <20070126175122.64D2616A500@hub.freebsd.org> <20070126230241.GA93074@ns.umpquanet.com> <20070126231913.GA12604@ayn.mi.celestial.com> <45BB2EEB.10204@infracaninophile.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45BB2EEB.10204@infracaninophile.co.uk> User-Agent: Mutt/1.5.11 OpenPKG/2.5 Cc: Subject: Re: [OT] Does "~" always point to $HOME? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd@celestial.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Jan 2007 17:08:53 -0000 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 -- INTERNET: bill@Celestial.COM Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676 ``A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.'' Robert Heinlein