Is there a Bourne-shell .logout script?

Jerry Peek jerryp at tektools.UUCP
Fri Dec 5 09:46:18 AEST 1986


In article <1051 at ptsfb.UUCP> rob at ptsfb.UUCP (Rob Bernardo) writes:
> In article <502 at cdx39.UUCP> jc at cdx39.UUCP (John Chambers) writes:
> >The C-shell runs a script called $home/.logout when you tell
> >it to log you out.  Is there any way to get the Bourne shell
> >to do something similar?
> 
> How about putting:
> 	trap "$HOME/.logout" 0
> in your .profile (or in /etc/profile)?

Not quite.  Unless your Bourne Shell is different than mine (4.3BSD),
this trap *starts a child Bourne Shell* to read the .logout file.
This means that shell variables and stuff you've set in your
login shell *won't be available* when the .logout file is read.

On the other hand, in the C-shell, the .logout file is read *directly by
the login shell*.  This lets your .logout test for the presence of shell
variables which were set in the login shell.  For instance, I set up some
shell variables that tell me whether the login shell came from a remote
machine (rlogin) or not, and do different things in those cases.

The fix is easy... use this "trap" instead:
 	trap ". $HOME/.sh_logout" 0
The leading "." tells the login Bourne shell to read the ".sh_logout" file
directly into itself, instead of spawning a child shell.  (I name mine
".sh_logout" because it has Bourne-shell contents that csh would choke on.)

--Jerry Peek, Tektronix, Inc.
US Mail:      MS 74-900, P.O. Box 500, Beaverton, OR 97077
uucp-style:   {allegra,decvax,hplabs,ihnp4,ucbvax}!tektronix!tektools!jerryp
Domain-style: jerryp at tektools.TEK.COM
Phone:        +1 503 627-1603



More information about the Comp.unix.questions mailing list