Using exit in a Bourne shell script
Will Martin
iunix1 at almsa-1.arpa
Tue Jul 19 11:43:30 AEST 1988
Back in February, there were some Info-UNIX discussions under the above
subject regarding methods of replacing the normal CTRL-D logoff with
a special script or procedure. One of the contributors mentioned this:
> From: Kathy Vincent <kathy at bakerst.uucp>
>
> trap '$HOME/.logout' 0
>
> Which is to say, "when you receive the logoff signal, execute $HOME/.logout
> first and THEN log off."
On our Sys V Unisys/Sperry I can do this, and get the ".logout" script to
execute when I hit a CTRL-D at the shell. It runs whatever I put in
".logout" and then logs me off the system. However, what I really want to
happen is to have a script execute that will then ask me "Do you REALLY
want to log off?" and then either return me to my shell, or allow me to
log off, depending on my answer. I want to do this because I am
constantly spawning subshells to do this or that task, and using CTRL-D
to end them. I often hit a CTRL-D at my top-level shell and get logged
off when I really did not want to log off -- I thought that I was under
my message-reading program, for example, and wanted to get back to it.
So I am willing to take the extra time to confirm it when I am finally
done and really, truly want to log off. I had thought at first that I
could do something with stty "eof" or suchlike settings that could make
my actual logoff character someting other than CTRL-D, so I could use
that to kill subshells, but not my top-level shell, but I've been told
that won't work.
Anybody have any advice on this subject? Is there a clean way to do what
I want? Or even a dirty way -- I'm pretty sloppy... :-) Can a script
executed at the "trap 0" point get back to the shell where the signal
originated, or is it too late by then? If so, could it cause another
top-level shell to be spawned, keeping all the environment I had before?
Will Martin
"wmartin at almsa-1.arpa"
More information about the Comp.unix.questions
mailing list