How to call .bash_logout on CentOS

0

1

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.

IanHacker

Posted 2019-10-07T16:51:51.657

Reputation: 103

No login? No logout. Your bash is not a login shell. – Cyrus – 2019-10-07T17:48:36.910

@Cyrus: Thanks, actually I know that, but could you tell me what to do? – IanHacker – 2019-10-08T00:09:56.120

Answers

0

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

trap "source ~/.bash_logout" EXIT

See: help trap

Cyrus

Posted 2019-10-07T16:51:51.657

Reputation: 4 356