Nathan Pk
Nathan Pk

Reputation: 749

shell script - printing result to a file and command prompt simultaneously

Is there a way to simultaneously print a result to command prompt and to a file?

for example:

    echo a >test.log

the output "a " must be written both to test.log file and command prompt simultaneously.

Upvotes: 1

Views: 472

Answers (3)

Satish
Satish

Reputation: 17467

Use tee which reads from standard input and writes to standard output and files.

Upvotes: 0

rainmaker
rainmaker

Reputation: 21

You want to use command tee

echo a |tee test.log

Upvotes: 0

Chris Seymour
Chris Seymour

Reputation: 85875

The command tee does this, most Linux distro's have this installed by default.

tee - read from standard input and write to standard output and files

Usage:

echo abc | tee test.log

Upvotes: 4

Related Questions