bash脚本无限循环一行语法 [英] bash script infinite loop one line syntax
问题描述
我有一个简单的bash脚本,它逐行读取文件并将其打印到屏幕上(从另一个SO答案中采用).
I have a simple bash script which reads from a file, line by line and prints it to the screen (adopted from another SO answer).
,而IFS =读-r行||[[-n"$ line"]];回显"$ line";睡2;完成<testfile.txt
我想使它成为无限循环,以便一旦到达文件末尾,便从头开始:
I want to make this an infinite loop so that once it reaches the end of the file, it starts from the beginning again:
我尝试在开始时添加一个 while true;
/ while [1];
/甚至一个 while:;
,但是没有一个这些工作.按下Enter键后,它会显示>
提示符.
I tried adding a while true;
/ while [ 1 ];
/ even a while :;
at the beginning, but none of these work. Upon pressing enter, it gives the >
prompt.
如何使此循环无限长并将其保持为单线?
How do I make this loop infinite and maintain it as a one-liner?
推荐答案
也许是这样吗?
while true; do while IFS= read -r line || [[ -n "$line" ]]; do echo "$line"; sleep 2; done < test.txt ; done
这篇关于bash脚本无限循环一行语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!