Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Why are you looping on $loop2 -eq 0 when it looks like you want $j -lt 11? Commented Jan 15, 2018 at 4:06
  • It'll be an infinite loop, but I want to be able to terminate it when the parent loops. I was just using $loop2 -eq 0 in hopes that changing the value of the variable would end the loop. But that didn't really pan out. Obviously this script is a simplification. My $j won't necessarily be 10 Commented Jan 15, 2018 at 4:11
  • Your nested loop runs in a subshell, so no change in variables in the outer loop will affect it. You'll have use something else, like a file, to tell the inner loop that the outer loop has changed. Commented Jan 15, 2018 at 4:12
  • The value of $j isn't really relevant to what I'm trying to do. I'm just trying to get the basic mechanics working. I want to have nested loops, and I want to be able to kill the nested loop and start it over when the parent loops. Commented Jan 15, 2018 at 4:13
  • I could use a file, but it seems a bit clunky. Is that the only option? I was also hoping "break" would help me, but it only works in the opposite scenario. (Killing the parent loop from within the nested loop.) One thing I noticed is that each "while" loop creates a new /bin/bash process with a unique PID. If there's a way to pinpoint the PID of the nested "while" loop, I could just kill the process at the end of the parent loop. But I couldn't figure out how to pinpoint it. Commented Jan 15, 2018 at 4:20