Why this command works:

ps -ax | grep mongo

but when I try set it to variable:

ubuntu# command='ps -ax | grep mongo'

ubuntu# echo $command
ps -ax | grep mongo

It gives me error, when calling:

ubuntu# $command
error: must set personality to get -x option

 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).
  • 1
    Any reason not to use pgrep?
    – muru
    Commented Aug 5, 2014 at 6:55
  • @muru ok, thank you: # command='pgrep mongo -la' Commented Aug 5, 2014 at 8:04

1 Answer 1


You can't execute a shell variable. You need to explicitly turn the $command variable into a command. The easiest way to do so is with the eval command. So: eval $command will work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .