使用临时文件_记录消息
#!/bin/bash
# tee命令:像是链接管道的T型接头,将来自STDIN的数据同时送往两处。
# 一处是STDOUT,另一处是tee命令所指定的文件名。
# -a选项:追加内容,不带该选项,会覆盖。
# using the tee command for logging
tempfile=test.v
echo "this is the start of the test" | tee $tempfile
echo "this is the second line of the test" | tee -a $tempfile
echo "this is the end of the test" | tee -a $tempfile
echo "*********** cat $tempfile ***********"
cat $tempfile
运行结果
this is the start of the test
this is the second line of the test
this is the end of the test
*********** cat test.v ***********
this is the start of the test
this is the second line of the test
this is the end of the test