[Chapter 11] 11.12 Pass History to Another Shell
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:36:15Z

#

| Chapter 11 The Lessons of History |

## 11.12 Pass History to Another Shell

The C shell, Korn shell, and bash automatically save a history of the commands you type. You can add your own commands to the csh and bash 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 but they 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 (11.11).

Here's an example. 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:

>     C shell   bash

>     % 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:

>     C shell   bash

>     % 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 (11.13) on the saved commands.

- JP

11.11 Picking Up Where You Left Off |  | 11.13 Shell Command-Line Editing