Shell Script: How to write a string to file and to stdout on console?

Catanzaro picture Catanzaro · Mar 28, 2014 · Viewed 106k times · Source

How to write a string to file and to stdout on console?

If I do

echo "hello" > logfile.txt

I view only hello in logfile.txt but how can I write hello also on console of Linux?

Answer

Biffen picture Biffen · Mar 28, 2014

Use the tee command:

echo "hello" | tee logfile.txt