Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6113773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:53:51+00:00 2026-05-23T14:53:51+00:00

If i have a do loop that looks something like for file in *txt;

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:53:52+00:00Added an answer on May 23, 2026 at 2:53 pm

    The expansion of *.txt is 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 bash as shown below:

    pax$ rm -rf *.xyzzy ; touch 1.xyzzy 2.xyzzy ; ls *.xyzzy
    1.xyzzy  2.xyzzy
    
    pax$ echo ===== ; for i in *.xyzzy ; do
    >    echo Processing $i
    >    echo ..... before touch ; ls *.xyzzy
    >    touch 3.xyzzy
    >    echo ..... after touch ; ls *.xyzzy
    >    echo =====
    > done
    =====
    Processing 1.xyzzy
    ..... before touch
    1.xyzzy  2.xyzzy
    ..... after touch
    1.xyzzy  2.xyzzy  3.xyzzy
    =====
    Processing 2.xyzzy
    ..... before touch
    1.xyzzy  2.xyzzy  3.xyzzy
    ..... after touch
    1.xyzzy  2.xyzzy  3.xyzzy
    =====
    
    pax$ ls *.xyzzy
    1.xyzzy  2.xyzzy  3.xyzzy
    

    You’ll note that the 3 file added during the first loop iteration doesn’t affect the loop at all, because the expansion has already been done at that point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks something like this where the first column
I have a file that looks like this: A B C D E 0
I have a List that is being filled with something like this in a
I have a loop that reads each line in a file using getline() :
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like
I have a text file I would like to read in that contains rows
I have a loop that's reading over a text file. Each time the loop
I'm pretty new to R.. I'm reading in a file that looks like this:
I have a file that look like this: 1 543423 34354 2 5654656 3423

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.