Possible Duplicate:
Storing output of command in shell variable

How can I put the result of jps | awk '$2~/Bootstrap/{print $1}' into a variable so that I can use with other commands?

marked as duplicate by Michael Mrozek Dec 3 '11 at 5:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from serverfault.com Dec 3 '11 at 4:43

This question came from our site for system and network administrators.


Wrap it in $( ... )

xyzzy=$(jps | awk '$2~/Bootstrap/{print $1}')
echo $xyzzy

this creates a subshell the output of which is captured into xyzzy.

  • 1
    "Nothing happens" – Zoredache Dec 3 '11 at 0:28
  • Note that any trailing newlines are deleted. .. This $(...) process is called Command Substitution and is one of the Shell Expansions: ✦ brace expansion ✦ tilde expansion ✦ parameter and variable expansion ✦ command substitution ✦ arithmetic expansion ✦ word splitting ✦ filename expansion – Peter.O Dec 3 '11 at 6:06