问题
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