前端之家收集整理的这篇文章主要介绍了
posix – 在shell脚本中检测stdin内容的存在,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在编写一个POSIX shell脚本,可能或可能不会从stdin接收输入(如foo.sh< test.txt,非交互式)。如何查看stdin中是否有任何
内容,以避免在读取-r行时停止播放?
@H_
404_1@
@H_
404_1@
如果我得到正确的问题,您可以尝试以下方式:
#!/bin/sh
if [ -t 0 ]; then
echo running interactivelly
else
while read -r line ; do
echo $line
done
fi
@H_
404_1@