1

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?

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227

1 Answers1

2

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 03 '11 at 00:28
  • Note that *any trailing newlines are deleted.* .. This `$(...)` process is called [Command Substitution](http://www.gnu.org/software/bash/manual/bashref.html#Command-Substitution) and is one of the [Shell Expansions](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions): ✦ brace expansion ✦ tilde expansion ✦ parameter and variable expansion ✦ command substitution ✦ arithmetic expansion ✦ word splitting ✦ filename expansion – Peter.O Dec 03 '11 at 06:06