Please help me to simplify my below script.
#!/bin/bash
LOG_FILE=/tmp/log.txt
echo "Hello"
echo "Hello" >> /tmp/log.txt
Is there anyway, that I can echo "Hello" to both screen and file with one single echo command ?
Please help me to simplify my below script.
#!/bin/bash
LOG_FILE=/tmp/log.txt
echo "Hello"
echo "Hello" >> /tmp/log.txt
Is there anyway, that I can echo "Hello" to both screen and file with one single echo command ?
echo "Hello" | tee log.txt
if you want to append the logg continuously, you can use
echo "Hello" | tee -a log.txt
-ilan
Thank you for your tip.
Let say if there are more than one command
echo "Hello" | tee >> log.txt
Date | tee >> log.txt
Is there a way that I can use to ouput both to screen and log file without re-using tee command ?
just use tee like ilan suggested. scrap the redirection operators
echo "Hello" | tee log.txt
date | tee -a log.txt
Sorry for not making my intention clear. I would like to get all the output of the script to screen and to the log file for all comands in my script.
I think I understand what you require...
This will capture all output from everything in script.sh to the screen and to log.txt without modifying script.sh
./script.sh |tee -a log.txt
Got it. Thank you much