Here's an example:
$ (newline=$'n'; bash -c "trap 'trap ERR; echo handler' ERR; set -e;${newline}/bin/false")
The handler will execute if I do any of the following:
I suspect bash has an optimization to just call exec if there's only one command, and the newline followed by a single command is triggering it.
I have circumstantial evidence: I ran under strace; earlier cmds will vfork then execve, but the last one just calls execv.
I ran into this with GNU make using .ONESHELL and a trap to print the exit code and log filename, but if the last thing fails the trap does not execute.
Thanks in advance.
برچسب:
نویسنده: استخدام کار