I doing a proof of concept script to automate getting a field from ps.
Currently, the script takes 2 imputs and I'm almost there but cannot get awk to recognize $2.
I want to invoke it like this: #./script init 2 (search for init and get PID). Obviously, $2 to awk will return PID but I'm trying to grab whichever field I want.
#! /bin/sh -x
ps -ef | grep $1 | grep -v grep | awk '{ print "$"$2"" }'
Any thoughts?