You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This only exits the subshell caused by the pipeline.
Problematic code:
foriin a b c;doecho hi | grep -q bye |breakdone
Correct code:
foriin a b c;doecho hi | grep -q bye ||breakdone
Rationale:
The most common cause of this issue is probably using a single | when || was intended. The reason this message appears, though, is that a construction like this, intended to surface a failure inside of a loop:
foriin a b c;dofalse|break;done;echo${PIPESTATUS[@]}
may appear to work:
$ foriin a b c;dofalse|break;done;echo${PIPESTATUS[@]}1 0
What's actually happening, though, becomes clear if we add some echos; the entire loop completes, and the break has no effect.
$ foriin a b c;doecho$i;false|break;done;echo${PIPESTATUS[@]}abc1 0
$ foriin a b c;dofalse|break;echo$i;done;echo${PIPESTATUS[@]}abc0
Because bash processes pipelines by creating subshells, control statements like break only take effect in the subshell.
Related resources:
Contrast with the related, but different, problem in this link.