bash script infinite loop one line syntax

自作多情 提交于 2021-01-29 15:16:19

问题


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).

while IFS= read -r line || [[ -n "$line" ]]; do echo "$line"; sleep 2; done < 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:

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?


回答1:


Maybe this ?

while true; do while IFS= read -r line || [[ -n "$line" ]]; do echo "$line"; sleep 2; done < test.txt ; done


来源:https://stackoverflow.com/questions/56260045/bash-script-infinite-loop-one-line-syntax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!