[comp.unix.questions] How to alias 'exit' in csh?

jdpeek@rodan.acs.syr.edu (Jerry Peek) (09/19/89)

I use 'su' to access an account that runs csh.  I want the '.logout' file to
be executed (sourced) when I end the shell.  So, I tried this in '.cshrc':
        set ignoreeof
        alias exit 'source ~/.logout; \exit'
It forces me to use exit to exit.  Typing exit sources ~/.logout, but then says
        "exit: command not found."

I read TFM pretty carefully, but all I've come up with is:
        set ignoreeof
        alias exit 'source ~/.logout; kill -9 $$'
which is pretty brutal.  Any better ideas?  This is on a Gould NP-1 running
UTX/32 (BSD4.3-like).  Thanks.

--Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY
  jdpeek@rodan.acs.syr.edu///JDPEEK@SUVM.BITNET///GEnie: J.PEEK1
  +1 315 443-3995

maart@cs.vu.nl (Maarten Litmaath) (09/20/89)

jdpeek@rodan.acs.syr.edu (Jerry Peek) writes:
\I use 'su' to access an account that runs csh.  I want the '.logout' file to
\be executed (sourced) when I end the shell.  So, I tried this in '.cshrc':
\        set ignoreeof
\        alias exit 'source ~/.logout; \exit'
\It forces me to use exit to exit.  Typing exit sources ~/.logout, but then says
\        "exit: command not found."

	alias	exit	'source ~/.logout; unalias exit; eval \exit'

...or just use `su -' to obtain a full login shell.
-- 
   creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam:
      it shouldn't have existed at all.    |maart@cs.vu.nl, mcvax!botter!maart

madd@bu-cs.BU.EDU (Jim Frost) (09/23/89)

In article <3301@solo9.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
|	alias	exit	'source ~/.logout; unalias exit; eval \exit'

Use:
	alias exit "source ~/.logout ; 'exit'"

Aliasing doesn't happen on quoted names, which I often make use of
when I really, really want to override my aliasing.

jim frost
software tool & die
madd@std.com

maart@cs.vu.nl (Maarten Litmaath) (09/23/89)

madd@bu-cs.BU.EDU (Jim Frost) writes:
\In article <3301@solo9.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes:
\|	alias	exit	'source ~/.logout; unalias exit; eval \exit'
\
\Use:
\	alias exit "source ~/.logout ; 'exit'"

solo12% alias exit "source ~/.logout ; 'exit'"
solo12% alias
exit    source ~/.logout ; 'exit'
solo12% exit
exit: Command not found.
solo12% 
-- 
   creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam:
      it shouldn't have existed at all.    |maart@cs.vu.nl, mcvax!botter!maart

cudcv@warwick.ac.uk (Rob McMahon) (09/23/89)

In article <38719@bu-cs.BU.EDU> madd@std.com writes:
>Use:
>	alias exit "source ~/.logout ; 'exit'"
>Aliasing doesn't happen on quoted names, which I often make use of when I
>really, really want to override my aliasing.

I replied to the author, but it occurred to me that this is a useful trick
that people might not know.  The above doesn't work, because quoting avoids
builtins as well as aliases, so it tries to look for a non-builtin command
called exit, which it doesn't find.  However

	alias exit "source ~/.logout ; ''exit"

does work, it avoids aliases but will still catch builtins.  This is useful if
someone nasty manages to alias your alias and unalias commands for you (with

	alias \unalias ...
	alias \alias ...

csh won't normally let you alias alias).  You just do

	''unalias alias
	unalias unalias

Rob
-- 
UUCP:   ...!mcvax!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv@uk.ac.warwick             ARPA:   cudcv@warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England