Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

Possible Duplicate:
Storing output of command in shell variable

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

share|improve this question

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

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

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.

Wrap it in $( ... )

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

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

share|improve this answer
Perfect - thankyou – naffcat Dec 2 '11 at 22:17
"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