Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

How could I capture the console output into a variable when running a utility so I can filter the text?

Example: I am trying to capture the console output when I type bitcoind so that I can filter out the rpcpassword and write it to a config file.

ubuntu@ip-172-31-3-49:~$ bitcoind
Error: To use bitcoind, you must set a rpcpassword in the configuration file:
It is recommended you use the following random password:
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
It is also recommended to set alertnotify so you are notified of problems;
for example: alertnotify=echo %s | mail -s "Bitcoin Alert"
share|improve this question
up vote 4 down vote accepted

Redirect the output to a file e.g.

bitcoind >~/bitcoind_output.txt 2>&1

This will put the output in a file in your home directory called bitcoind_output.txt

share|improve this answer
Cheers Glenn - well spotted with the typo :) – NGRhodes Feb 21 '14 at 20:43
You'll want the 2>&1 after the >~/bitcoind_output.txt. – minerz029 Feb 21 '14 at 20:56
@minerz029 That was the trick bitcoind >~/bitcoind_output.txt 2>&1 – Brandon Clark Feb 21 '14 at 22:41

To capture the output into a variable:

output=$(bitcoind 2>&1)
share|improve this answer
curious: what does the variable hold, and what goes to the screen? – glenn jackman Feb 21 '14 at 22:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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