It's pretty easy to type one too many CTRL-d characters and log out of a
Bourne shell without meaning to.
The C shell has an
shell variable (
that won't let you log out with
So do the Korn shell and
set -o ignoreeof
Here's a different sort of solution for the Bourne shell.
When you end the shell, it asks if you're sure.
If you don't answer yes, a new shell is started to replace your old one.
a file like the C shell's
that will be read whenyour Bourne shell exits . (
name in an
environment variable (
too-you'll need it later:
TTY=`tty`; export TTY
trap '. $HOME/.sh_logout; exit' 0
(Your system may need
Put the following lines in your new
exec < $TTY
echo "Do you really want to log out? \c"
case "$ans" in
*) exec $HOME/bin/-sh ;;
The last line is some trickery to start a new
login shell (
closes your tty (
before reading your
exec < $TTY
reconnects the shell's standard input to your
Note that if your system is
slow, you may not get the reminder
message for a couple of seconds-you might forget that it's coming and
That hasn't been a problem where I've tested this.
If it is for you though, replace the
with a program
that times out and gives a default answer after a while.
There may be some Bourne shells that need other tricks-and others that don't
need these tricks-but this should give you an idea of what to do.