Can a command be stuffed into History?

Robert Hartman rhartman at thestepchild.sgi.com
Tue Apr 9 10:44:19 AEST 1991


In article <1991Apr5.184054.20966 at ssd.kodak.com> weimer at ssd.kodak.com writes:
>
>In article <SQUASH.91Apr4184954 at heat.math.ufl.edu> 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 <CR> 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 <CR> and then run SECOND_THING
>
>weimer at 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



More information about the Comp.unix.wizards mailing list