If i have a do loop that looks something like
for file in *txt; do {something on $file that results in another file ending with txt being created}; done
Will that cause an infinite loop? I’m rather afraid to test it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The expansion of
*.txtis typically done by the shell before any commands are run. So, no, it won’t result in an infinite loop.I say “typically” since it depends, of course, on the shell you’re using. But every shell I’ve had experience with works this way, including
bashas shown below:You’ll note that the
3file added during the first loop iteration doesn’t affect the loop at all, because the expansion has already been done at that point.