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?

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

- JP