bug-bash
[Top][All Lists]
Advanced

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

bash does not run exit traps if the last command is a kill builtin that


From: Emanuele Torre
Subject: bash does not run exit traps if the last command is a kill builtin that kills bash (`kill "$$"')
Date: Fri, 29 Apr 2022 18:58:29 +0200

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin'
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc'
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout'
-DNON_INTERACTIVE_LOGIN_SHELLS
uname output: Linux t420 5.15.35-1-lts #1 SMP Wed, 20 Apr 2022
11:49:16 +0000 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:
        Bash does not run `EXIT' traps if the last command is the kill
        builtin kills that kills the shell.

        Maybe because of some incorrect optimisation?

Repeat-By:
        bash-5.1$ bash -c 'trap echo\ x EXIT; kill "$$"'
        Terminated

        bash-5.1$ bash -c 'trap echo\ x EXIT; { kill "$$" ;}'
        Terminated

        bash-5.1$ bash -c 'x () { trap echo\ x EXIT; kill "$$"; }; x'
        Terminated

        bash-5.1$ bash -c 'trap echo\ x EXIT; echo a; kill "$$"'
        a
        Terminated

        bash-5.1$ bash -c 'trap echo\ x EXIT; kill "$$"; :'
        x
        Terminated

        bash-5.1$ bash -c 'trap echo\ x EXIT; /bin/kill "$$"'
        x
        Terminated

        bash-5.1$ bash -c 'x () { trap echo\ x EXIT; kill "$$"; }; x; :'
        x
        Terminated

        I have been able to reproduce this bug in bash5, bash4, and
        bash3.
        The EXIT trap is run correctly in bash2.



reply via email to

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