O'Reilly logo

Using csh & tcsh by Paul DuBois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reusing and Editing Commands

We've just seen some techniques for typing filenames easily. The following sections show how to use some of the other features that the shell provides for reducing typing: reusing and editing commands, using aliases to create command shortcuts, and command substitution.

The Shell's History List

The shell has a mechanism for maintaining a history list. That is, it remembers the commands you execute and allows you to rerun them with a few keystrokes. Suppose you're analyzing two data sets, reviewing the results of each analysis before printing the data:

% sed -e 's/^\(...\) *\([0-9][0-9]*\)/\2 \1/' data1 > temp
% anova Height Weight < temp | more
% anova Height Weight < temp | lpr
% sed -e 's/^\(...\) *\([0-9][0-9]*\)/\2 \1/' data2 > temp
% anova Height Weight < temp | more
% anova Height Weight < temp | lpr

There is a lot of redundancy in these commands. You can get the same results with less typing by reusing commands that you've already run:

% sed -e 's/^\(...\) *\([0-9][0-9]*\)/\2 \1/' datal > temp
% anova Height Weight < !$ | more         Run anova, using temp as input file
% ^more^lpr                               Change more to lpr and rerun command
% !sed:s/datal/data2                      Rerun sed, changing data1 to data2
% !?more                                  Rerun most recent command that contains more
% !?lpr                                   Rerun most recent command that contains lpr

Before you try reusing commands, make sure that your shell is remembering them. Try the history command to display your history list:

% history 209 rm junk 210 pushd 211 ls 212 vi ch01 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required