bug-bash
[Top][All Lists]
Advanced

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

return exit code in EXIT trap


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

Is it known behavior that return without a parameter will not set the exit code from the last command when called from the EXIT trap?

   $ cat -n exitReturnBug.sh
         1      #!/usr/bin/bash
         2      function shouldReturnFalse() {
         3              false
         4              return
         5      }
         6      trap 'shouldReturnFalse && echo "woops"' EXIT
   $ ./exitReturnBug.sh
   woops

If I change line 4 to "return $?" it will not print "woops" which is the correct behavior.

I tested this in 5.0.17 and 5.1.16.

--BobG



reply via email to

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