简体   繁体   中英

bash script infinite loop one line syntax

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?

也许这样吗?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM