0

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

Usage:
 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).
2
  • 1
    Any reason not to use pgrep?
    – muru
    Aug 5, 2014 at 6:55
  • @muru ok, thank you: # command='pgrep mongo -la' Aug 5, 2014 at 8:04

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.