Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!mailrus!uwmcsd1!marque!uunet!mcvax!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.questions Subject: Re: Using exit in a Bourne shell script Message-ID: <567@philmds.UUCP> Date: 21 Jul 88 07:14:45 GMT References: <16540@brl-adm.ARPA> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 79 In article <16540@brl-adm.ARPA> iunix1@almsa-1.arpa (Will Martin) writes: >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 >> >> 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 [some stuff deleted] >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? I tried the 'trap ....' command and noticed that in the .logout script a read from the terminal was not honoured, i.e. read answer didn't put anything in answer (there was no waiting for my response). Obviously the stdin of the shell has already been closed. Then I tried to fake it by reading from /dev/tty; you have to do something like for i in 1 do read answer done