posix – 在shell脚本中检测stdin内容的存在

我正在编写一个POSIX shell脚本,可能或可能不会从stdin接收输入(如foo.sh< test.txt,非交互式)。如何查看stdin中是否有任何内容,以避免在读取-r行时停止播放?
如果我得到正确的问题,您可以尝试以下方式:
#!/bin/sh
if [ -t 0 ]; then
    echo running interactivelly
else
    while read -r line ; do
        echo $line
    done
fi

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...