Newsgroups: comp.unix.questions Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Subject: Re: How to alias EXIT or any CSH command Message-ID: <1991Apr3.150825.7074@athena.mit.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology References: <1991Apr1.165435.4687@berlioz.nsc.com> Date: Wed, 3 Apr 91 15:08:25 GMT Lines: 57 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