linuxbashdebian

How do I edit bash_logout for all users on a system


Now I know I can edit bash_logout to execute commands once the user types exit, but only for a specific user by editing their bash_logout in their home directory. But how do I edit this for all users?


Solution

  • bash doesn't recognize a system-wide logout script.* The best you can do is create a world-readable file like /etc/bash_logout, and recommend that users add . /etc/bash_logout to their personal ~/.bash_logout files.

    The only system-wide configuration file bash recognizes is /etc/profile for login shells. You could add

    trap 'on_logout' EXIT
    

    (where on_logout is the name of a function you define that contains the desired log-out code) to this file and hope users don't reset the handler. (Technically, /etc/profile is shared amongst all POSIX-compatible shells, so don't put any bash-specific code in such a handler.)


    * By default. There is a compile-time option to enable the use of /etc/bash.bash_logout, though.