LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 10-06-2012, 06:06 AM   #1
masuch
Member
 
Registered: Sep 2011
Location: /dev/null
Distribution: ubuntu 64bits
Posts: 129

Rep: Reputation: Disabled
Question 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
 
Old 10-06-2012, 06:48 AM   #2
masuch
Member
 
Registered: Sep 2011
Location: /dev/null
Distribution: ubuntu 64bits
Posts: 129

Original Poster
Rep: Reputation: Disabled
Sorry, I solved it by:
PID_PS=( `ps aux|grep "${_PROC1}" |grep grep --invert-match|awk '{printf $2;printf "\n"; }'` )
 
Old 10-06-2012, 07:00 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,264
Blog Entries: 54

Rep: Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841Reputation: 2841
Please don't. Try PIDS=($(pgrep $nameoftheprocess)).
 
1 members found this post helpful.
Old 10-06-2012, 09:35 AM   #4
masuch
Member
 
Registered: Sep 2011
Location: /dev/null
Distribution: ubuntu 64bits
Posts: 129

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
Please don't. Try PIDS=($(pgrep $nameoftheprocess)).
thanks, ppid is much better.
 
  


Reply

Tags
array, bash, command, output, process


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign find command output to a varaible rohan1977 Linux - Newbie 1 04-30-2012 01:35 AM
Creating array from command output (bash shell script) Rizla Programming 5 01-26-2011 10:47 PM
[Bash] array `ls` output aoresearch Linux - Newbie 5 11-11-2009 08:21 AM
bash script: how to assign an output (not the result) to a variable? Singing Banzo Programming 8 10-01-2006 06:29 PM
Assign command output to a varible. wilku Linux - Newbie 3 03-26-2005 11:56 AM


All times are GMT -5. The time now is 09:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration