11
8
So I've been wondering how to run these two lines of code everytime I close an open instance of Terminal:
history -c
cat /dev/null > ~/.bash_history
I export HISTFILE=5
on startup, but still want to flush that out when I'm done.
I've tried looking around a bit in a couple of places, and haven't had much luck.
I run Linux Mint, and would also note here that I ran into a similar issue with .bash_profile
; eventually, I discovered I needed to place all start up code in .bashrc
, so maybe that has something to do with it. Here's my .bash_logout
file:
#!/bin/bash
# ~/.bash_logout: executed by bash(1) when login shell exits.
#this does nothing on exit...
echo 'logout'; sleep 2s
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
history -c
cat /dev/null > ~/.bash_history
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
I've tried re-arranging this script many ways, I'm not sure if I don't understand how bash works, and if any of this is running in the first place. Does the fact that I run Xserver
make bash consider Terminal something that isn't a log-out on exit?
It does say that I am not logged in, which would make sense:
$> shopt login_shell
login_shell off
As a general comment, if you’re testing whether or not a shell config script is getting run, I recommend you put the
echo
command at the start, before it does anything else that could interfere with theecho
getting run. An error could cause the script to exit before it gets to the end. – Chris Page – 2012-04-09T22:34:09.250I was assuming from the way you phrased this, and the fact that you’re checking for SHLVL=1, that you already verified that it’s a login shell. Is it? What does
shopt login_shell
say? – Chris Page – 2012-04-10T00:24:04.487