LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 07:06 AM   #1
masuch
Member
 
Registered: Sep 2011
Location: /dev/null
Distribution: ubuntu 64bits
Posts: 135

Rep: Reputation: 1
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, 07:48 AM   #2
masuch
Member
 
Registered: Sep 2011
Location: /dev/null
Distribution: ubuntu 64bits
Posts: 135

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

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

Original Poster
Rep: Reputation: 1
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 02:35 AM
Creating array from command output (bash shell script) Rizla Programming 5 01-26-2011 11:47 PM
[Bash] array `ls` output aoresearch Linux - Newbie 5 11-11-2009 09:21 AM
bash script: how to assign an output (not the result) to a variable? Singing Banzo Programming 8 10-01-2006 07:29 PM
Assign command output to a varible. wilku Linux - Newbie 3 03-26-2005 12:56 PM


All times are GMT -5. The time now is 06:07 AM.

Main Menu
Advertisement
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