Most shells can save a history of the commands you type (Section 30.12). You can add your own commands to some shells' history lists without retyping them. Why would you do that?
You might have a set of commands that you want to be able to recall and reuse every time you log in. This can be more convenient than aliases because you don't have to think of names for the aliases. It's handier than a shell script if you need to do a series of commands that aren't always in the same order.
You might have several shells running (say, in several windows) and want to pass the history from one shell to another shell (Section 30.12).
Unfortunately, this isn't easy to do in all shells. For instance, the new pdksh saves its history in a file with NUL-separated lines. And the tcsh history file has a timestamp-comment before each saved line, like this:
#+0972337571 less 1928.sgm #+0972337575 vi 1928.sgm #+0972337702 ls -lt | head
Let's look at an example for two of the shells that make history editing easy. Use the csh command history -h, or the bash command history -w, to save the history from a shell to a file. Edit the file to take out commands you don't want:
% mail -s "My report" bigboss $ mail -s "My report" bigboss ... ... % history -h > history.std $ history -w history.std % vi history.std $ vi history.std ...Clean up history... ...Clean up history...
Read that file into another shell's history list with the csh command source -h or the bash command history -r:
% source -h history.std $ history -r history.std % !ma $ !ma mail -s "My report" bigboss mail -s "My report" bigboss
Of course, you can also use bash interactive command-line editing (Section 30.14) on the saved commands.
-- JP
Copyright © 2003 O'Reilly & Associates. All rights reserved.