[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Revisiting Error handling (errexit)

From: Lawrence Velázquez
Subject: Re: Revisiting Error handling (errexit)
Date: Tue, 05 Jul 2022 19:19:20 -0400
User-agent: Cyrus-JMAP/3.7.0-alpha0-713-g1f035dc716-fm-20220617.001-g1f035dc7

On Tue, Jul 5, 2022, at 6:34 PM, Yair Lenga wrote:
> I probably did not described the intended behavior clearly. I believe 
> both cases should behave identical under errfail. The loop will ‘break’ 
> on the first iteration (false when word = a). Same for the all looping 
> commands. I believe this is consistent with if-then-else-if, when an 
> error in the then or else block will result in terminating (‘breaking’) 
> the if. 

It's only consistent if your notion of consistency is "terminate
all compound commands immediately".  This kind of works for "if"
but changes "for" and "while" in a very fundamental way.  Your
initial description of "treat a; b; c like a && b && c" implies

    if condition; then a; b; c; fi

should behave like

    if condition; then a && b && c; fi


    for word in words; do a; b; c; done

should behave like

    for word in words; do a && b && c; done

but it turns out what you apparently want is

    for word in words; do a && b && c || ! break; done

which is a larger change than you let on.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]