help-bash
[Top][All Lists]
Advanced

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

Re: reset a trap upon use


From: bill-auger
Subject: Re: reset a trap upon use
Date: Fri, 24 Nov 2023 13:17:13 -0500

yes, it could have been done several ways - i am adapting existing code though -
i would have needed to add that "if it's mounted" check or suppress STDERR -
call me pedantic; but id rather not have the function called multiple times,
if it will do nothing all but the first time

per your example, i would prefer this:
> trap cleanup EXIT
> setup
> cleanup
> trap - EXIT
> 
> call the boot script

but it was originally like this:
> setup() {
>   trap cleanup INT TERM RETURN
>   do work...
>   cleanup
> }
> 
> cleanup() {
>   trap - INT TERM RETURN
>   do cleanup...
> }

i now have like this:
> setup() {
>   trap cleanup INT TERM RETURN
>   do work...
>   trap - INT TERM RETURN
>   cleanup
> }

if only because it makes the intention more clear, where and why the trap is
needed, and that the cleanup should be done automatically, only due to an
INT, TERM, or early RETURN - semantically, those are the reasons why the magic
spell should be cast



reply via email to

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