How can I parse a record found in /etc/passwd into variables?

I am working with the Oracle 10.2.0.3 job scheduler on Solaris 10, and unfortunately, the scheduler executes scripts in such a way that several default shell environment variables are not defined. For example, $HOME, $USER, and $LOGNAME are missing.

How can I parse the appropriate record in /etc/passwd into the above variables? For example, when the output from "grep oracle /etc/passwd" is:

oracle:x:100:1978::/usr/oracle:/bin/ksh

I need to parse the information so that I can manually export the following variables:

export HOME=/usr/oracle
export USER=oracle
export LOGNAME=oracle

I'm looking for something generic that will enable me to search for any record in /etc/passwd and parse it properly.

Thanks,

J

export HOME=$(nawk -F":" '/^oracle/{print $(NF-1)}' /etc/passwd)
export USER=$(nawk -F":" '/^oracle/{print $1}' /etc/passwd)
export LOGNAME=$(nawk -F":" '/^oracle/{print $1}' /etc/passwd)

If you know the user name then the only thing you need to look up is the home directory, in ksh this can be evaluated with ~username, eg eval ~\$USER.

This should work:

grep "^oracle:" /etc/passwd | read s
USER=`echo $s | cut -d: -f1`
LOGNAME=$USER
HOME=`echo $s | cut -d: -f6`

That's the problem. When running under the Oracle Scheduler, the "normal" shell environment variables are not fully populated. Actually, only two shell variables are populated, and they are not among the list I mentioned above. I'm having to "backfill" what is missing.

This looks interesting. I'll check it out.

Thanks! This works great!

That will only work in ksh. But if that works, so would:
grep "^oracle:" /etc/passwd | IFS=":" read user xpass uid gid gcos home shell