Getting ps -ef result as a variable

I am trying to create a script in linux - bash, being new to it. I would like to assign the output of the command ps -efas a variable. Can anyone help me with this? Unfortunately, the trivial myVariable = ps -efdoes not work.

+3
source share
4 answers

Do you want to:

myVariable=`ps -ef`

or

 myVariable=$(ps -ef)

Note the absence of spaces around the '=' sign.

+1
source
myVariable=$(ps -ef)
# or
myVariable=`ps -ef`
+4
source

Try:

 myVariable=`ps -ef`   # back tic, upper left on most keyboards

Then the real pleasure of parsing the results can begin

+2
source

myVariable = `ps -ef` or myVariable = $ (ps -ef)

0
source

All Articles