Re: return exit code in EXIT trap

2022-08-08 Thread Robert E. Griffith
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 becaus

Re: return exit code in EXIT trap

2022-08-08 Thread Chet Ramey
On 8/8/22 4:22 PM, Robert Elz wrote: Date:Mon, 8 Aug 2022 14:45:06 -0400 From:Chet Ramey Message-ID: <253ddd1c-2d2d-1ac1-f4bb-a611896ce...@case.edu> | > Having "exit" mean "exit $?-as-it-was" | > in those circumstances makes some sense, having return do

Re: return exit code in EXIT trap

2022-08-08 Thread Robert Elz
Date:Mon, 8 Aug 2022 15:16:41 -0400 From:"Robert E. Griffith" Message-ID: <887ca26e-1c9e-f500-1bd9-6d339ab5a...@junga.com> | I think a better solution to that would have been to leave return alone | and instead allow the trap to access the $? value of the last co

Re: return exit code in EXIT trap

2022-08-08 Thread Robert Elz
Date:Mon, 8 Aug 2022 14:45:06 -0400 From:Chet Ramey Message-ID: <253ddd1c-2d2d-1ac1-f4bb-a611896ce...@case.edu> | > Having "exit" mean "exit $?-as-it-was" | > in those circumstances makes some sense, having return do that is absurd. | | You are going to hav

Re: return exit code in EXIT trap

2022-08-08 Thread Robert E. Griffith
Understanding now that traps are more literally like inserting an eval, what makes return in the top level trap string special is that there are two script paths behind it so its reasonable the the coder of the trap to ask from which last statement do I want to preserve the exit code. The shell

Re: return exit code in EXIT trap

2022-08-08 Thread Chet Ramey
On 8/8/22 1:53 PM, Robert Elz wrote: Date:Mon, 8 Aug 2022 10:34:50 -0400 From:Chet Ramey Message-ID: <6ea53781-b6a8-8be1-2314-a25904727...@case.edu> | It's a logical conclusion from the requirement that the trap action be | executed as if you had dropped an

Re: return exit code in EXIT trap

2022-08-08 Thread Robert Elz
Date:Mon, 8 Aug 2022 10:34:50 -0400 From:Chet Ramey Message-ID: <6ea53781-b6a8-8be1-2314-a25904727...@case.edu> | It's a logical conclusion from the requirement that the trap action be | executed as if you had dropped an `eval action' into the function, or | whe

Re: return exit code in EXIT trap

2022-08-08 Thread Chet Ramey
On 8/6/22 12:05 AM, Robert Elz wrote: I am actually astounded by all of this - both by what is in the standard, and the way Chet interpreted it. The language in the standard for return was clearly based upon the idea that it should act just the same as exit, which is not really appropriate. It

Re: return exit code in EXIT trap

2022-08-08 Thread Chet Ramey
On 8/6/22 2:44 PM, Robert Elz wrote: It is possible (and seems so, from messages in this thread) that bash allows a return in the trap string (not in a function called in that string) if the trap occurs while executing a function (then the return applies to that function). Every shell allows t

Re: return exit code in EXIT trap

2022-08-06 Thread Robert E. Griffith
On 8/6/22 14:44, Robert Elz wrote: ... bash allows a return in the trap string (not in a function called in that string) if the trap occurs while executing a function (then the return applies to that function). ... Yes! that is what I was missing.  Years ago when I wrote my debugger, I must hav

Re: return exit code in EXIT trap

2022-08-06 Thread Robert Elz
Date:Sat, 6 Aug 2022 12:02:07 -0400 From:"Robert E. Griffith" Message-ID: <5a091673-5e70-baee-0874-1c8c5ec88...@junga.com> | Where can we use 'return' directly in a trap script? What am I not getting? I suspect that if you want specified behaviour, the answer is no

Re: return exit code in EXIT trap

2022-08-06 Thread Koichi Murase
2022年8月7日(日) 1:02 Robert E. Griffith : > Where can we use 'return' directly in a trap script? What am I not getting? It is described in the very original thread: https://lists.gnu.org/archive/html/bug-bash/2014-03/msg00053.html -- Koichi

Re: return exit code in EXIT trap

2022-08-06 Thread Robert E. Griffith
Hmmm.. I just got confused when I went to do a test... $ trap 'echo hi; return' SIGUSR2 $ kill -SIGUSR2 $$ hi bash: return: can only `return' from a function or sourced script $ $ echo $BASH_VERSION 5.0.17(1)-release I also confirmed the same error in the DEBUG trap where you s

Re: return exit code in EXIT trap

2022-08-06 Thread Robert E. Griffith
On 8/5/22 21:49, Koichi Murase wrote: 2022年8月3日(水) 21:19 Robert E. Griffith : That was an interesting read. The illuminating point for me was the statement to the effect of "the POSIX specification is not meant to describe what it correct or rational, but what historically has been implemented s

Re: return exit code in EXIT trap

2022-08-05 Thread Robert Elz
I am actually astounded by all of this - both by what is in the standard, and the way Chet interpreted it. The language in the standard for return was clearly based upon the idea that it should act just the same as exit, which is not really appropriate. Even at first glance, an "exit" executed an

Re: return exit code in EXIT trap

2022-08-05 Thread Koichi Murase
2022年8月3日(水) 21:19 Robert E. Griffith : > That was an interesting read. The illuminating point for me was the > statement to the effect of "the POSIX specification is not meant to > describe what it correct or rational, but what historically has been > implemented so that existing scripts will rema

Re: return exit code in EXIT trap

2022-08-05 Thread Martin D Kealey
On Wed, 3 Aug 2022 at 08:06, Koichi Murase wrote: > 2022年8月3日(水) 5:57 Chet Ramey : > >> Until then, I'm going by the plain language of the standard. It seems >> more strange that POSIX would have intended this to mean only a `return' in >> the actual action string (A) instead of while the trap ac

Re: return exit code in EXIT trap

2022-08-03 Thread Robert E. Griffith
That was an interesting read. The illuminating point for me was the statement to the effect of "the POSIX specification is not meant to describe what it correct or rational, but what historically has been implemented so that existing scripts will remain unbroken". This makes me appreciate Chet'

Re: return exit code in EXIT trap

2022-08-02 Thread Koichi Murase
2022年8月3日(水) 5:57 Chet Ramey : > On 8/2/22 4:18 PM, Robert E. Griffith wrote: > > Is there a reason why POSIX would want the return behavior to of function > > down the stack to behave differently when in a trap? Seems strange to me. > > I don't remember if Koichi ever opened up a bug with the Aust

Re: return exit code in EXIT trap

2022-08-02 Thread Robert E. Griffith
https://getyarn.io/yarn-clip/cea30edb-a7a6-465b-bc51-3d53d9281447 It was worth the wait:) --BobG On 8/2/22 16:57, Chet Ramey wrote: On 8/2/22 4:18 PM, Robert E. Griffith wrote: The first (getyarn...) link renders as a blank page for me. What it is supposed to be? https://getyarn.io/yarn-

Re: return exit code in EXIT trap

2022-08-02 Thread Chet Ramey
On 8/2/22 4:18 PM, Robert E. Griffith wrote: The first (getyarn...) link renders as a blank page for me. What it is supposed to be? https://getyarn.io/yarn-clip/cea30edb-a7a6-465b-bc51-3d53d9281447 Is there a reason why POSIX would want the return behavior to of function down the stack to

Re: return exit code in EXIT trap

2022-08-02 Thread Robert E. Griffith
Oh darn, I have been writing bash scripts for a long time and have never found a novel bug. I was hoping this would be my first:) The first (getyarn...) link renders as a blank page for me. What it is supposed to be? Is there a reason why POSIX would want the return behavior to of function d

Re: return exit code in EXIT trap

2022-08-02 Thread Chet Ramey
On 8/2/22 3:38 PM, Robert E. Griffith wrote: > 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? https://getyarn.io/_nuxt/f66cb012eec875e1f9262fd77ecdf31e.svg https://lists.gnu.org/archive/html/bug-bash/2020-04/

return exit code in EXIT trap

2022-08-02 Thread Robert E. Griffith
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