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

Re: shell kung-fu with set -e, return codes and i/o redirection in while read ... loop



Jonas Meurer <jonas@freesources.org> writes:

> On 20/07/2009 Boyd Stephen Smith Jr. wrote:
>> In <[🔎] 20090719235708.GB22995@resivo.wgnet.de>, Jonas Meurer wrote:
>> >- in cryptdisks_{start|stop} only one device is setup anyway. here I
>> >  simply don't use set -e and check for the error code instead.
>> 
>> While I understand your goal here, I think you should try and accomplish it 
>> while leaving the entire script "set -e".  It helps prevent errors from 
>> cascading.  Even if you are checking return values for everything now, you 
>> might not be so disciplined with changes in the future.
>
> i see your point and indeed i already reverted the change to not set -e
> the scripts. instead I now use a if statement for the invokation of
> handle_crypttab_line_{start,stop}, do post-cryptsetup stuff (umount)
> directly in the while loop, and exit with log_action_end_msg $ret at the
> end of the while loop. that way the script always stops inside the while
> loop, with or without error.
>
> greetings,
>  jonas

Beware that if you call a function from a complex expression (if,
while, ||, &&, |) then that function will not use "set -e". Inside the
function you then need to check every return code again or errors will
cascade.

MfG
        Goswin


Reply to: