awk question

For the following code:

ps auwx | awk -v "PID=${PID}" '$2 == PID {print $LN}'

Two points to clarify:

  1. Is the -v flag for declaring we're going to work with a variable?
  2. Does the $LN stands for current line? If so, what's wrong with $0? Any difference between them?
    Thanks

Hard to tell what you want - so I did this:

ps auwx | awk -v "PID=${PPID}" '$2 == PID {print }'
xxxxxxx  598114  0.0  0.0  956 1048      - A    08:48:02  0:00 sshd: xxxxxxx@pts/1
prdrept:logs :ps auwx | awk -v "PID=$$" '$2 == PID {print }'
xxxxxxx  479452  0.0  0.0  752  800  pts/1 A    08:48:02  0:00 -ksh

this is using AIX, different systems could handle this differently.
1) LN does not show to be a defined variable in my awk. (I even checked the gawk manual to see if it were there.) Why use $0 when just a simple print will default to the present line.

2) I was not sure if you wanted the current process ($$) or the parent process ($PPID} - ${PID}, was not defined in my version of AIX.

Hi "awk", Thanks and sorry for not clarifying enough.

The line is part of a running and working bash script on Linux.
PID is a local variable and the awk line is using its value to print the relevant line from ps.
I don't want to change the code (unless I have too), rather understand why it is used that way.

to simplify it, it is something like:

function foo()
{
   local MY_PID=""
   #...
   MY_PID=get_my_pid
   LINE=`ps auwx | awk -v "PID=${MY_PID}" '$2 == PID {print $LN}'`
   do_something "${MY_PID}"
}

So, I understand the -v is used to declare variable, since ${MY_PID} will not be resolved inside 'single quotes' - right?

I still don't understand what is the $LN for?
Could anyone clarify? Is it a mistake, that works the same way as print $XXX works ???

Thanks

anyone knows something about the $LN ?

It's not allowed to bump your thread to the top and pushing other peoples threads to the bottom.
Please read our rules.

The $ sign is used to print fields and AFAIK LN is not an awk variable.....

Regards

Thanks
sorry for the bump:o