Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to combine the following into a nifty "one liner":

echo "free -m" > /tmp/dC4v2cK
bash /tmp/dC4v2cK
share|improve this question

closed as off topic by womble, John Gardeniers, Michael Hampton, Ward, Iain Sep 25 '12 at 21:16

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

What exactly are you trying to accomplish here? Seems like you're trying to take the long way around... – EEAA Aug 13 '12 at 22:53
I think I figured it out, would simply piping work: echo "free -m" | bash – Justin Aug 13 '12 at 22:59
Or just "free -m". Why the extra bash shell? – EEAA Aug 13 '12 at 23:00
Because what is instead of the echo statement is dynamic. – Justin Aug 13 '12 at 23:03
up vote 5 down vote accepted

Or if you really want a subshell:

/bin/bash -c "free -m"
share|improve this answer

I think you are looking for eval (as in foo='free -m'; eval $foo). Keep in mind that doing something like this has security implications if $foo is coming from an untrusted source then you could inadvertently do bad things. For example what if someone managed to get this line to happen. foo='rm -rf /'

$ help eval
eval: eval [arg ...]
    Execute arguments as a shell command.

    Combine ARGs into a single string, use the result as input to the shell,
    and execute the resulting commands.

    Exit Status:
    Returns exit status of command or success if command is null.
share|improve this answer

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