[comp.unix.questions] How to alias EXIT or any CSH command

nelson@berlioz.nsc.com (Taed Nelson) (04/02/91)

I have reason to desire an alias for the CSH command EXIT.  Since
  the executable version doesn't exist anywhere, I can't do:
	alias exit 'MY_STUFF_HERE; /usr/bin/exit'
  or whatever.

Anyone have a solution?

asg@sage.cc.purdue.edu (Bruce Varney) (04/02/91)

In article <1991Apr1.165435.4687@berlioz.nsc.com> nelson@berlioz.nsc.com (Taed Nelson) writes:
}
}I have reason to desire an alias for the CSH command EXIT.  Since
}  the executable version doesn't exist anywhere, I can't do:
}	alias exit 'MY_STUFF_HERE; /usr/bin/exit'
}  or whatever.
}
}Anyone have a solution?
Try this:
alias normal_exit 'exit'
alias exit 'MY_STUFF_HERE; normal_exit'

They have to be in that order I believe, but that should work.
Course, if you used bash (a MUCH better shell) you could do:
alias exit='MY_STUFF_HERE; builtin exit'

If you would like info on bash, just ask me.
asg@sage.cc.purdue.edu
			Bruce
---------
sar.casm \'sa:r-.kaz-*m\ \sa:r-'kas-tik\ \-ti-k(*-)le-\ n [F sarcasme, fr. 
   LL sarcasmos, fr. Gk sarkasmos, fr. sarkazein to tear flesh, bite the lips 
   in rage, sneer, fr. sark-, sarx flesh; akin to Av thwar*s to cut] 1: a 
   cutting, hostile, or contemptuous remark : GIBE 2: the use of caustic or 
   ironic language - sar.cas.tic aj

                                   ###             ##
Courtesy of Bruce Varney           ###               #
aka -> The Grand Master                               #
asg@sage.cc.purdue.edu             ###    #####       #
PUCC                               ###                #
;-)                                 #                #
;'>                                #               ##

nelson@berlioz.nsc.com (Taed Nelson) (04/02/91)

>}I have reason to desire an alias for the CSH command EXIT.

>alias normal_exit 'exit'
>alias exit 'MY_STUFF_HERE; normal_exit'

Nope, still gives an Alias Loop...

shuque@eniac.seas.upenn.edu (Sumon Huque) (04/02/91)

In article <1991Apr1.165435.4687@berlioz.nsc.com> nelson@berlioz.nsc.com (Taed Nelson) writes:
>
>I have reason to desire an alias for the CSH command EXIT.  Since
>  the executable version doesn't exist anywhere, I can't do:
>	alias exit 'MY_STUFF_HERE; /usr/bin/exit'
>  or whatever.
>
>Anyone have a solution?


Try this:

alias exit 'MYSTUFF; kill -HUP $$'

Recall, the variable $ contains the process number of the current shell.

asg@sage.cc.purdue.edu (Bruce Varney) (04/02/91)

In article <1991Apr1.205905.9095@berlioz.nsc.com> nelson@berlioz.nsc.com (Taed Nelson) writes:
}>}I have reason to desire an alias for the CSH command EXIT.
}
}>alias normal_exit 'exit'
}>alias exit 'MY_STUFF_HERE; normal_exit'
}
}Nope, still gives an Alias Loop...
Try the following sequence of commands then:

% bash
bash$ alias exit='MY_STUFF_HERE; builtin exit'
;-)


---------
sar.casm \'sa:r-.kaz-*m\ \sa:r-'kas-tik\ \-ti-k(*-)le-\ n [F sarcasme, fr. 
   LL sarcasmos, fr. Gk sarkasmos, fr. sarkazein to tear flesh, bite the lips 
   in rage, sneer, fr. sark-, sarx flesh; akin to Av thwar*s to cut] 1: a 
   cutting, hostile, or contemptuous remark : GIBE 2: the use of caustic or 
   ironic language - sar.cas.tic aj

                                   ###             ##
Courtesy of Bruce Varney           ###               #
aka -> The Grand Master                               #
asg@sage.cc.purdue.edu             ###    #####       #
PUCC                               ###                #
;-)                                 #                #
;'>                                #               ##

christos@theory.tn.cornell.edu (Christos S. Zoulas) (04/02/91)

In article <9223@mentor.cc.purdue.edu> asg@sage.cc.purdue.edu (Bruce Varney) writes:
>In article <1991Apr1.205905.9095@berlioz.nsc.com> nelson@berlioz.nsc.com (Taed Nelson) writes:
>}>}I have reason to desire an alias for the CSH command EXIT.
>}
>}>alias normal_exit 'exit'
>}>alias exit 'MY_STUFF_HERE; normal_exit'
>}
>}Nope, still gives an Alias Loop...

No flames please...

alias exit 'MY_STUFF_HERE; kill -9 $$'

christos
-- 
+------------------------------------------------------------------------+
| Christos Zoulas         | 389 Theory Center, Electrical Engineering,   |
| christos@ee.cornell.edu | Cornell University, Ithaca NY 14853.         |
| christos@crnlee.bitnet  | Phone: (607) 255 0302 |  Fax: (607) 254 4565 |

arthur@sgi.com (Arthur Evans) (04/03/91)

In article <1991Apr1.165435.4687@berlioz.nsc.com> nelson@berlioz.nsc.com (Taed Nelson) writes:
>
>I have reason to desire an alias for the CSH command EXIT.  Since
>  the executable version doesn't exist anywhere, I can't do:
>	alias exit 'MY_STUFF_HERE; /usr/bin/exit'
>  or whatever.
>
>Anyone have a solution?

I imagine so.  Try:

	alias exit 'echo blurg ; ""exit'

I know, I know--it don't make a whole boatload of
sense, but it worked on my system.  Hope it works
on yours ... 

-arthur

--
Arthur Evans -- Information Decorator, Akbar and Jeff's Documentation Hut

mjm@eleazar.dartmouth.edu (Andy Behrens) (04/03/91)

nelson@berlioz.nsc.com (Taed Nelson) writes:
>I have reason to desire an alias for the CSH command EXIT.  Since
>  the executable version doesn't exist anywhere, I can't do:
>	alias exit 'MY_STUFF_HERE; /usr/bin/exit'
>  or whatever.

Well, since nobody else has come up with a solution that generalizes
to commands other than exit:

	set Exit=exit
	alias exit 'MY_STUFF_HERE; $Exit'


--
If you've got a hammer,			       If the only tool you have
find a nail.				    is a hammer, you tend to see
(George Bush, January 29, 1991)			every problem as a nail.
							(Abraham Maslow)
+-------------------+
|  Andy Behrens     |                   or: andyb%coat.com@dartmouth.edu
|  andyb@coat.com   |                    bitnet: andyb%coat.com@dartcms1
+-------------------+       uucp: {uunet,rutgers}!dartvax!coat.com!andyb
Burlington Coat, HC 61 Box 1B, Lebanon, N.H. 03766        (603) 448-5000
    

jik@athena.mit.edu (Jonathan I. Kamens) (04/03/91)

In article <1991Apr1.165435.4687@berlioz.nsc.com>, nelson@berlioz.nsc.com (Taed Nelson) writes:
|> I have reason to desire an alias for the CSH command EXIT.  Since
|>   the executable version doesn't exist anywhere, I can't do:
|> 	alias exit 'MY_STUFF_HERE; /usr/bin/exit'
|>   or whatever.

  The wrong ways to do it (i.e. these won't work):

	# causes an alias loop
	alias normal_exit 'exit'
	alias exit 'MY_STUFF_HERE; normal_exit'

	# doesn't allow the shell to clean up or do .logout
	alias exit 'MY_STUFF_HERE; kill -9 $$'

The silly ways to do it (i.e. posted by people who didn't know the right way,
and knew it):

	% bash
	bash$ alias exit='MY_STUFF_HERE; builtin exit'

Ways to do it that just might work, but are sub-optimal:

	# Shell might behave strangely when it gets a HUP, there's really no
	# reason to do it this way other than not understanding the shell
	# enough to do it right.
	alias exit 'MYSTUFF; kill -HUP $$'

And finally, the ways that will do the right thing (why they do the right
thing is explained below):

	set Exit=exit
	alias exit 'MY_STUFF_HERE; $Exit'

	alias exit 'echo blurg ; ""exit'

  Alias substitution happens before variables are expanded.  Alias
substitution happens before quoting is dealt with.  Therefore, the the two
solutions above prevent an alias loop by convincing the shell not to notice
that the command being run is aliased until it is too late to do substitution.
Despite what the person who posted the last solution above said, it *does*
make sense.

  Now, as for what I think is the "best" way to do it:

	alias exit 'MY_STUFF_HERE; \exit'

Back-slashing a character quotes it, which makes the shell treat it
differently when doing alias expansion.  This is how I've always seen alias
loops avoided.  Using "" is just about the same.  Using a variable to put the
variable in is just a bit of overkill.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

jik@athena.mit.edu (Jonathan I. Kamens) (04/04/91)

In article <1991Apr3.150825.7074@athena.mit.edu>, jik@athena.mit.edu (Jonathan I. Kamens) writes:
|>   Now, as for what I think is the "best" way to do it:
|> 
|> 	alias exit 'MY_STUFF_HERE; \exit'
|> 
|> Back-slashing a character quotes it, which makes the shell treat it
|> differently when doing alias expansion.  This is how I've always seen alias
|> loops avoided.  Using "" is just about the same.  Using a variable to put the
|> variable in is just a bit of overkill.

  Of course, my answer is wrong :-(

  The rest of my posting was right, but when I went to post my own entry into
the competition, I screwed up when I was testing it, as Gillmer Derge kindly
pointed out to me in E-mail.  I forgot that the check for built-ins takes
place before quoting is removed from strings.

  The - alias exit 'MY_STUFF_HERE; ""exit' - appears to be the most correct
solution.

  Sorry about that.

  Incidentally, I agree with Bruce Varney that a better solution is to use
another shell.  The quoting rules for csh and tcsh are arcane and magical, and
in many ways unplanned.  Yuck.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710