[Top][All Lists]

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

Re: return exit code in EXIT trap

From: Robert E. Griffith
Subject: Re: return exit code in EXIT trap
Date: Mon, 8 Aug 2022 18:00:01 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 8/8/22 16:38, Robert Elz wrote:
There's no need for anything to make that work, when the trap action
starts running $? is set to whatever it was just previously, and the
code there can save and/or use that value however it sees the need.

Well I'll be. I had to write a script to test it because I was so sure that at least USR1 and USR2 did not.

Its a shame that for a 'feature' that is not even required, 'return' has been made quirky so that reusing good code in a trap handler breaks that code.

FYI: here is script I just used ...

   $ cat bin/trapExitCodeTest.sh
   #!/usr/bin/env bash
   if [ "$1" == "slowerror" ]; then
        sleep 0.5
        exit 45;
        trap 'echo "$sigToTest: last cmd exit = $?"' $sigToTest
        bash -c "$0 slowerror"
   sleep 0.2
   kill -$sigToTest $child
   sleep 1

   $ bin/trapExitCodeTest.sh
   USR1: last cmd exit = 45


reply via email to

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