Re: Using an awk program Ronald J Marchand typed (on Wed, Sep 08, 2004 at 06:32:24PM -0500):
| Using an awk program, I am trying to set the values of pid and pseudo in a
| shell script to be used in other commands. So far I have:
| :
| logname=digna
| pid=
| pseudo=
| ps -ef | grep xcrt | awk -v user=$logname -v pid=$pid -v pseudo=$pseudo '
| ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { print $1,$2 }
| ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { pid = $2 }
| ( $1 == user && $8 == "/usr/lib/merge/xcrt" ) { pseudo = $6 }
| '
| echo $pid
| echo $pseudo
| exit
|
| This program executes fine. It just doesn't set pid & pseudo.
| Could some kind soul show mercy and explain the error?????
A parent does not inherit from its child. Whatever you set inside the
awk program is unknown outside it.
Your grep is superfluous, BTW.
Try this:
eval `ps -ef | awk -v user=$LOGNAME '
$1~user && $8~"/usr/lib/merge/xcrt" {print "pid=" $2 " pseudo=" $6}
'`
echo PID is $pid and PSEUDO-TTY is $pseudo
--
JP |