awk script

Jonathan I. Kamens jik at athena.mit.edu
Tue Mar 19 05:31:18 AEST 1991


In article <Mar.18.11.52.08.1991.16656 at pilot.njin.net>, drears at pilot.njin.net (Dennis G. Rears) writes:
|> CMD='artemis'
|> ME=`whoami`
|> PROC=`ps -ef|grep /${CMD}|            \

  This seems like a problem to me.  Programs in a ps listing don't always have
the full path of the executable listed.  With the slash in the command above,
you're requiring the full path listing, which is probably going to lose in
some cases.

|> awk '{ $1 == ${ME} && $8 != "grep"  $2 }' `

  First of all, the conditions should be outside the curly braces.  Second,
you can't just give a field and expect awk to print it -- you have to tell awk
to print it.  Third, few versions of awk allow you to access environment
variables inside awk, and that's what you're trying to do above, since the
${ME} inside the single quotes is going to be interpreted by awk, not by the
shell.  Try this:

    awk '$1 == '${ME}' && $8 != "grep" {print $2}'`

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.questions mailing list