寻找类似 "tee" 但每次写入的目标文件是哪个 open/closes?

Looking for something like "tee" but which open/closes the target file with each write?

我有类似 mycommand | tee -a mylogfile.log 的东西,但是因为日志文件驻留在磁盘上,可能会一遍又一遍地重新安装,所以我想要 tee open/close 文件每次写入(例如,每一行)。有没有办法完成这样的事情?

这将打开和关闭每行 mylogfile.log

mycommand | while IFS= read -r line; do printf "%s\n" "$line" | tee -a mylogfile.log; done

使用bash,可以稍微简化一下:

mycommand | while IFS= read -r line; do tee -a mylogfile.log <<<"$line"; done