0

I have two bash functions: tsoc and loopex

I have put them in a diffchecker so you can see that they are almost identical: https://www.diffchecker.com/nygtg1l4

When I run loopex, I get the type of output I want: "Orphaned" or "Passed" for each item in the outer loop. However, for tsoc, a function that is nearly identical, I get "Orphaned" printed after every line, whether "Passed" or "Orphaned", which is not desired.

Outputs

loopex (correct)

$ loopex  
Checking 1: Orphaned
Checking 2: Orphaned
Checking 3: Passed
Checking 4: Orphaned
Checking 5: Orphaned

tsoc (incorrect)

$ tsoc
Checking ./assignments/documents/Module2.pdf: Passed
Orphaned
Checking ./announcements.html: Passed
Orphaned
Checking ./projects.html: Passed
Orphaned
Checking ./assignments1.html: Passed
Orphaned
Checking ./lectures1.html: Passed
Orphaned
Checking ./random.txt: Orphaned
Checking ./index.html: Passed
Orphaned
Checking ./news.html: Passed
Orphaned

As you can see, Orphaned is printing after every line in tsoc and I'm absolutely baffled as to why. The only think I can think of is that piping to a while loop is somehow breaking the logic of the continue statement. However, in the manpage for continue, it states that it works for 'while' and 'for' loops.

I've been at this for hours and I'm at my wits end. Any light you can shed on the situation would be greatly appreciated.

TW80000
  • 1,507
  • 1
  • 11
  • 18
  • 1
    Pipelines introduce sub-shells. `continue` cannot cross sub-shell boundaries. See how all the loops in [Bash FAQ 001](http://mywiki.wooledge.org/BashFAQ/001) use redirection instead of pipelines? That's why. Do the same. – Etan Reisner Jul 08 '15 at 15:40
  • Questions should include enough code to act as a minimal reproducer **in the question itself**. – Charles Duffy Jul 08 '15 at 15:40
  • 1
    Also, BashFAQ #24: http://mywiki.wooledge.org/BashFAQ/024 – Charles Duffy Jul 08 '15 at 15:40

0 Answers0