help-bash
[Top][All Lists]
Advanced

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

5.2.15(1)-release: RETURN trap not executed in cmd subst if last stateme


From: Jens Schmidt
Subject: 5.2.15(1)-release: RETURN trap not executed in cmd subst if last statement of fct is not builtin
Date: Sat, 6 Jul 2024 13:41:01 +0200
User-agent: Mozilla Thunderbird

Today I came across this one:

  [copy-on-select-2]$ echo $BASH_VERSION
  5.2.15(1)-release
  [copy-on-select-2]$ foo() { trap 'echo foo' RETURN; /bin/echo bar; }
  [copy-on-select-2]$ foo
  bar
  foo
  [copy-on-select-2]$ baz=$( foo )
  [copy-on-select-2]$ echo "<$baz>"
  <bar>

I guess that Bash execve's the "/bin/echo" since it runs in a command
substitution and the trap does not get executed, hence.

As a work-around, one can tweak function foo so that the last command
is not an external one, like this:

  [copy-on-select-2]$ foo() { trap 'echo foo' RETURN; /bin/echo bar; return $?; 
}
  [copy-on-select-2]$ foo
  bar
  foo
  [copy-on-select-2]$ baz=$( foo )
  [copy-on-select-2]$ echo "<$baz>"
  <bar
  foo>

Would this be a bug?

Should I report it separately on bug-bash?

Thanks!



reply via email to

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