将交互式 bash 会话通过管道传输到文件

Piping an interactive bash session to a file

这个问题是关于 Piping an interactive session to a file.

但由于我无法在 post 中发表评论,所以我会在这里提问。 我在 bash 脚本中有以下代码:

tee -a file.log | (ls -a )| tee -a file.log

程序运行正常,但脚本退出需要按回车键

脚本是否可以在没有用户操作的情况下退出?

注意:ls -a 只是我在这里用来说明问题的示例。

将第一个 tee 设置为空输入,这样它就不会等待标准输入,如下所示:

tee -a file.log <<< "" | (ls -a )| tee -a file.log

echo | tee -a file.log | (ls -a )| tee -a file.log

tee -a file.log < "" | (ls -a )| tee -a file.log