【发布时间】:2014-07-21 02:05:58
【问题描述】:
我正在用 bash 做一些有趣的事情
我在下面写了脚本:
#!/bin/bash
while :
do
if [ -s /tmp/file.txt ]; then
for line in $(cat /tmp/file.txt)
do
echo $line
#May be some commands here
done
fi
done
我的file.txt的内容是:
1 True
2 Flase
如果命令cat /tmp/file.txt 已完成(我的意思是所有行都已读取)并且echo $line 和其他命令已完成然后break 不定式while : 循环,我该如何说脚本?
谢谢
【问题讨论】:
-
你为什么设置
while循环?你可以从这段代码中删除它,它是无用的。只有当你想测试文件的内容是否准备好时,在这种情况下你应该使用sleep 10来避免你的 CPU 过载 -
这是必需的,因为有些命令在后台运行。我想说的是,这些命令的 pid 在工作时是无限的
标签: bash loops process while-loop infinite-loop