Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 bash 脚本,它提示用户输入“读取”。如果 stdout 或 stderr 被传送到终端以外的其他东西,我想禁止这一步。那可能吗?
您可以使用命令 test -t <filedescriptor no.> 检查文件描述符是否为 tty(附加到终端)。如果是,您可以提示用户。如果不是,则输出可能在某处通过管道传输或重定向。
if test -t 1 ; then echo stdout is a tty fi