LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to assign output from bash command ps to array ? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-assign-output-from-bash-command-ps-to-array-4175430818/)

masuch 10-06-2012 06:06 AM

how to assign output from bash command ps to array ?
 
Hi,

I have a command:
ps aux|grep "$nameoftheprocess" |grep grep --invert-match|awk '{printf $2; }

as an example: one result returns 3 PIDs like following:
769777057724 # which is 7697 7705 7724

I would like to assign those values into array. How to do it ?

Thank you,
Kind Regards,
Martin

masuch 10-06-2012 06:48 AM

Sorry, I solved it by:
PID_PS=( `ps aux|grep "${_PROC1}" |grep grep --invert-match|awk '{printf $2;printf "\n"; }'` )

unSpawn 10-06-2012 07:00 AM

Please don't. Try PIDS=($(pgrep $nameoftheprocess)).

masuch 10-06-2012 09:35 AM

Quote:

Originally Posted by unSpawn (Post 4798717)
Please don't. Try PIDS=($(pgrep $nameoftheprocess)).

thanks, ppid is much better.


All times are GMT -5. The time now is 09:18 PM.