【问题标题】:Piping an interactive bash session to a file将交互式 bash 会话通过管道传输到文件
【发布时间】:2017-12-14 18:51:30
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

    标签: linux bash pipe tee


    【解决方案1】:

    将第一个 tee 设置为采用空输入,这样它就不会在 stdin 上等待,如下所示:

    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
    

    【讨论】:

    • 请注意,您无法使用此方法提供常规输入,因此将其用于 shell 或解释器可能无法按预期工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 2013-05-06
    相关资源
    最近更新 更多