LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   more help with bash script please (https://www.linuxquestions.org/questions/linux-newbie-8/more-help-with-bash-script-please-247707/)

poiuytrewq 10-26-2004 09:14 PM

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

homey 10-26-2004 09:28 PM

Using backticks ( ` ) like this ....

#!/bin/bash

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

echo "$pid"

poiuytrewq 10-26-2004 09:36 PM

edit:

i spoke too soon, works great

poiuytrewq 10-26-2004 09:38 PM

edit: i spoke too soon

homey 10-26-2004 09:41 PM

Quote:

$ echo $pid
I have echo "$pid"

poiuytrewq 10-26-2004 09:43 PM

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)

homey 10-26-2004 09:57 PM

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


All times are GMT -5. The time now is 04:29 AM.