shadyabhi
shadyabhi

Reputation: 17234

Redirect to file as well as to STDOUT in bash

I've a long bash script with multiple echo statements.

I had a requirement to redirect bash script's output to a file without using redirection from bash shell. I could accomplish that by doing:

exec 1>>/tmp/output

How do I do something like both redirecting to a file and not stopping to output in STDOUT?

I don't want to edit each and every echo statement to accomplish it.

Upvotes: 0

Views: 365

Answers (2)

k107
k107

Reputation: 16450

Use tee

your_script | tee /tmp/output

Upvotes: 4

shadyabhi
shadyabhi

Reputation: 17234

Got the help from #bash IRC.

exec > >(tee file)

Upvotes: 1

Related Questions