Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!sgi!shinobu!odin!thestepchild!rhartman From: rhartman@thestepchild.sgi.com (Robert Hartman) Newsgroups: comp.unix.wizards Subject: Re: Can a command be stuffed into History? Message-ID: <1991Apr9.004419.21127@odin.corp.sgi.com> Date: 9 Apr 91 00:44:19 GMT References: <1991Apr5.184054.20966@ssd.kodak.com> Sender: news@odin.corp.sgi.com (Net News) Distribution: comp Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 51 In article <1991Apr5.184054.20966@ssd.kodak.com> weimer@ssd.kodak.com writes: > >In article you write: >|> Could some kind soul tell me how to write an alias (or a script) >|> which, after having done something (eg. an lpr command) >|> places on the history list, a particular command. >|> My intention is to later execute this command with !! . >|> If this cannot be done, is it possible to have the alias type a >|> command to the Unix prompt, so that I can hit later to execute it? > >Not exactly what you asked, but in csh you could just do: > >alias cmd 'FIRST_THING;echo "SECOND_THING";set x=$<;SECOND_THING' > >this will run FIRST_THING, print SECOND_THING (not at a prompt), >wait for and then run SECOND_THING > >weimer@ssd.kodak.com ( Gary Weimer ) Rather than put it on the history list or in a variable, you could have your alias create a new alias for you. For instance, I use the following alias for cd: alias cd 'set pd=$cwd;chdir \!*;alias $cwd:t "cd $cwd";echo $cwd;u $ulist' This does, in order: saves the pathname of the current (soon to be previous) directory in $pd changes directory creates an alias using the basename of the new directory as the name; when I want to cd to that directory again in future, I can just invoke its basename as a command echoes the pathname of the new directory unaliases directory names that are also names of commands, such as "man" and "sccs" BTW, here are some of my other "navigational" aliases: alias pd 'set qd=$cwd;chdir $pd;set pd=$qd;echo $cwd' alias . 'echo $cwd' alias .. 'cd ..' alias , pd The aliasing scheme in csh accepts "." characters. Not so with ksh, so the equivalent trick is a little more complicated. Last time I did it, I had to use a shell procedure named CD for the guts of the thing. BTW, I was also able to give myself a directory history in sh using a shell procedure that creates new ones. -r