I have a shell script with many echo expressions. I want to prefix each line of output with time and date.
So, I replaced every
echo "Some text1"
echo "Some text2"
from
echo "`date +%y/%m/%d_%H:%M:%S`:: some text1"
echo "`date +%y/%m/%d_%H:%M:%S`:: some text2"
This is pretty ugly. Do I need to create an alias (or C # define analog in C) to make it cleaner.
Obviously something like:
DATE=`date +%y/%m/%d_%H:%M:%S`
echo "$DATE:: some text1"
echo "$DATE:: some text2"
... will not work, because in this case, DATE is calculated only once, and each echo has the same date.
I am thinking of replacing each echo with a call to the print function, which makes a prefix. I want to know if anyone has any other / better ideas.
source
share