【问题标题】:Check whether stderr is a pipe in bash检查stderr是否是bash中的管道
【发布时间】:2009-07-29 21:54:05
【问题描述】:

我有一个 bash 脚本,它提示用户输入“读取”。如果 stdout 或 stderr 被传送到终端以外的其他东西,我想禁止这一步。这可能吗?

【问题讨论】:

    标签: bash pipe stderr


    【解决方案1】:

    您可以使用命令 test -t 检查文件描述符是否为 tty(附加到终端)。如果是,您可以提示用户。如果不是,则输出可能在某处通过管道传输或重定向。

    if test -t 1  ; then
      echo stdout is a tty
    fi
    

    【讨论】:

    • 谢谢!正是我想要的。
    猜你喜欢
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2022-12-16
    相关资源
    最近更新 更多