LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-26-2004, 09:14 PM   #1
poiuytrewq
Member
 
Registered: Jul 2004
Posts: 107

Rep: Reputation: 15
more help with bash script please


i cant for the life of me figgure out how to get the output of this into a variable:

ps -A | grep myprocessname | awk '{print $1}'

i can get it in as a string, ive tried all sorts of stuff, but i would just like to have the output of that in a variable called "pid"

please and thanks
 
Old 10-26-2004, 09:28 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Using backticks ( ` ) like this ....

#!/bin/bash

pid=`ps -A | grep firefox | awk '{print $1}'`

echo "$pid"
 
Old 10-26-2004, 09:36 PM   #3
poiuytrewq
Member
 
Registered: Jul 2004
Posts: 107

Original Poster
Rep: Reputation: 15
edit:

i spoke too soon, works great

Last edited by poiuytrewq; 10-26-2004 at 09:43 PM.
 
Old 10-26-2004, 09:38 PM   #4
poiuytrewq
Member
 
Registered: Jul 2004
Posts: 107

Original Poster
Rep: Reputation: 15
edit: i spoke too soon

Last edited by poiuytrewq; 10-26-2004 at 09:41 PM.
 
Old 10-26-2004, 09:41 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Quote:
$ echo $pid
I have echo "$pid"
 
Old 10-26-2004, 09:43 PM   #6
poiuytrewq
Member
 
Registered: Jul 2004
Posts: 107

Original Poster
Rep: Reputation: 15
sorry, it all works, i just forgot to change firefox to the name of my program
thanks for the help, it works perfectly
(sidenote: using ""'s perserves whitespeace, but withouth them the content wil still be output)
 
Old 10-26-2004, 09:57 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Yeah, I'm used to having something else along with the variable.
Like this...
echo "This is your pid: $pid"
 
  


Reply


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
Bash script Linh Programming 4 04-21-2004 05:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script brian0918 Programming 7 06-12-2003 06:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 10:18 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration