On 29/07/2020 16:07, Geoff Clare wrote:
Harald van Dijk <a...@gigawatt.nl> wrote, on 29 Jul 2020:
On 29/07/2020 09:45, Geoff Clare wrote:
It's only easy because (most/all?) shells take the easy option and do
a lexical analysis of the command to be substituted.
trap (without -p) in a command substitution prints the trap actions of the
parent shell in bash, busybox ash, gwsh, ksh and yash. Of these, only
busybox ash does it by lexical analysis.
Perhaps things have changed since 2009 when this first came up, but
(as I reported in bug 53) at that time, ksh93 was the only shell I
could find which handled things like:
var=trap; save_traps=$($var)
and
save_traps=$(trap; true)
correctly.
I do not know which shells were the ones you tried at the time, but you
should have included bash. Those exact commands print the trap actions
of the parent shell at least as far back as bash 2.05b from 2002.
Cheers,
Harald van Dijk