![](/img/trans.png)
[英]Bash- loop through each character in a string to check for specific pattern
[英]Bash- How to check if file is empty in a loop
我需要检查Bash文件是否为空,
如果它是空的,继续跟踪他,直到有东西被写入。
如果写入内容,则将其回显到屏幕并停止检查文件内容。
for [ -s diff.txt ]; do
echo "file is empty - keep checking it "
done
echo "file is not empty "
cat diff.txt
为什么不用一段while
?
while ! [ -s diff.txt ]; do
echo "file is empty - keep checking it "
sleep 1 # throttle the check
done
echo "file is not empty "
cat diff.txt
循环将运行只要! [ -s diff.txt ]
! [ -s diff.txt ]
是真的。 如果你愿意,你可以使用until
而不是while
删除否定( !
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.