Path: utzoo!attcan!uunet!mcvax!hp4nl!botter!ark.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Using exit in a Bourne shell script Message-ID: <1322@ark.cs.vu.nl> Date: 19 Jul 88 18:01:35 GMT References: <16540@brl-adm.ARPA> Reply-To: maart@cs.vu.nl (Maarten Litmaath) Organization: VU Informatica, Amsterdam Lines: 57 In article <16540@brl-adm.ARPA> iunix1@almsa-1.arpa (Will Martin) writes: \... \On our Sys V Unisys/Sperry I can do this [trap '. $HOME/.logout' 0], \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. \... If so, could it cause another \top-level shell to be spawned, keeping all the environment I had before? Environment is ok, you're going to lose the local shell variables. Put the following in your .profile: TTY=`tty` export TTY trap '. $HOME/.logout' 0 Put the following in your .logout: /bin/echo -n 'Do you really want to logout? ' case "`gets < $TTY`" in y*) echo Bye! ;; *) exec xq sh -sh -i < $TTY ;; esac The TTY stuff is necessary, because sh has already closed your tty before it's going to source .logout. :-( The 'xq' program, whose source is below, executes its first argument with the name of the second argument, causing the sh to believe it's a login shell. Good luck with it! /* * xq.c */ main(argc, argv) int argc; char **argv; { if (argc < 3) { puts("Wadda ya thinka this!"); exit(1); } execvp(argv[1], &argv[2]); perror(argv[1]); exit(1); } -- I'd rather live in Russia |Maarten Litmaath @ Free U Amsterdam: than in South-Africa... |maart@cs.vu.nl, mcvax!botter!ark!maart