Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Jan 2007 13:30:46 -0800
From:      Garrett Cooper <youshi10@u.washington.edu>
To:        freebsd-questions@freebsd.org
Subject:   Re: [OT] Does "~" always point to $HOME?
Message-ID:  <45BBC486.6060507@u.washington.edu>
In-Reply-To: <20070127171255.GA13120@ayn.mi.celestial.com>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
-----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-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45BBC486.6060507>