LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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: 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, 06: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, 07:00 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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: 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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:31 PM.

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
Open Source Consulting | Domain Registration