how to find out the home directory of a user??

Hi all,
I would like to know how to find out the home directory of a particular user..
eg,
If am the root , then my Home directory will be /
if say am just a user logging into the terminal then my home dir would change,
so accordingly i would like to know how to find it out...

I know that the shell prompt changes accordingly but how to figure it out through a command?, I mean is there any command to find out the home directory of a particular user(be it the root or an average joe!!!)

there are many ways....

$ cd
$ pwd

$ echo $HOME

$ grep username /etc/passwd

hth,
DN2

Hi,
I forgot to mention, i would like to know how to incorporate it into a script..
I mean how to give input to $HOME so that depending upon the username the $HOME gives me the home dir...

I must also mention, i will not be running as root...

>find_user="somebody"

>cat /etc/passwd | grep "$find_user" | cut -c":" -f6

awk only

awk -F: -v v="user" '{if ($1==v) print $6}' /etc/passwd

how do you authenticate your users? local files, ldap or nis? if local files, give an exampel of your "/etc/passwd".

on solaris works something like this:

# grep username /etc/passwd | cut -d ":" -f6
/export/home/username

I dont think awk and all will be necessary,(its for some ppl who dont know about awk )
Not yet taught ,i suppose!!!!(so will have to make do with "if and else" only....

ive just written this pls have a look!!!

for i in $*
do
cat /etc/passwd |grep $i | cut -d ":" -f 6
done

Here how to i specify a constraint stating that if no arg is passed it should return an error?
I tried with simple ,
if test -z $i ; then
echo "error"
else
//proceed...

how do i get something like this working?

You should avoid cat of a single file. Grep can read the file just fine, you don't need cat to feed it.

#!/bin/sh

case $# in 0) echo foo: need an argument >&2; exit 1;; esac

for i in "$@"; do
  grep "$i" /etc/passwd | cut -d: -f6
done

Pay attention to the quoting; you want to avoid throwing an error if somebody calls your script with a string with spaces in it, or (worse yet) an actual shell command which gets executed and has dire side effects (think `rm -rf $HOME` in backticks).

You should probably actually grep "^$i:" to avoid accidentally printing the wrong information because of a coincidental substring match. (True story: grep era /etc/passwd would find "System Operator" and print root's home directory on BSD.)