Using exit in a Bourne shell script
Maarten Litmaath
maart at cs.vu.nl
Wed Jul 20 04:01:35 AEST 1988
In article <16540 at brl-adm.ARPA> iunix1 at 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 at cs.vu.nl, mcvax!botter!ark!maart
More information about the Comp.unix.questions
mailing list