This is exactly what tee for:
echo "Hello World!" | tee textfile
For multiple outputs you can use
( echo "Hello World!" echo "next line blah blah" ) | tee textfile
or use the append parameter with tee .
echo "Hello World!" | tee textfile echo "next line blah blah" | tee -a textfile
source share