0

I'm trying to call my own .bash_logout on CentOS when a user logs out. However, even when an 'exit' command is sent, .bash_logout is NOT called/executed (it just logs out).

On CentOS, when I type 'exit' and click on 'Return', the system displays 'exit', and then nothing happens. On other linux systems, when I type 'exit' and click on 'Return', the system displays 'logout', and then it calls my .bash_logout.

Is there any way to call .bash_logout on exit on CentOS? (Or, any way to execute a script on exit.)

Any suggestion would be helpful. Thank you in advance.

2
  • No login? No logout. Your bash is not a login shell.
    – Cyrus
    Commented Oct 7, 2019 at 17:48
  • @Cyrus: Thanks, actually I know that, but could you tell me what to do?
    – IanHacker
    Commented Oct 8, 2019 at 0:09

1 Answer 1

0

Add this to your ~/.bashrc and start a new bash:

trap "source ~/.bash_logout" EXIT

See: help trap

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .