Tuesday (not so) Tiny Techie Tip

csh(1) and tcsh(1) command history

Perhaps one of the main things which made BSD UNIX more popular than AT&T's version was the new shell developed at Berkeley by Bill Joy (Sun Microsystems) and others. Unlike the Bourne shell (sh(1)), csh(1) provided a number of features not directly related to writing shell programs whose sole purpose was to make interactive use easier. These features include job control, aliases, and command history. tcsh(1) is pretty much a proper superset of csh, and all the features I'll talk about here work in either shell.

Note that in the process of having all these great interactive features added, the c-shell became much less well suited to shell programming than its older but more spry aunt, sh(1).

To find out exactly why you shouldn't write programs in csh(1), check out Tom Christiansen's rant:

Csh Programming Considered Harmful

But we're not talking about shell programming, we're talking about interactive use, specifically command history, so here we go...

Command Retrieval

The most commonly used feature of csh command history is "!!" (pronounced "bang bang") which recalls the previous command:


% date
Mon Nov 25 13:52:36 PST 1996
% !!
date
Mon Nov 25 13:52:52 PST 1996

Note that when you use any history retrieval, the resulting command is echoed to stdout before execution so you can see what you've done.

"!!" is available even if you have history disabled. To see if history is enabled, look at the "history" shell variable:


% echo $history
history: Undefined variable.
% set history=100
% echo $history
100

The number stored in the "history" variable indicates how many commands will be saved for retrieval. To see what commands can be retrieved, use the "history" csh built-in command (see csh_builtins(1)):


% history
    41  cd /vobs/Rm/ApeCpt/cpt
    42  vi cpt.c
    43  clearmake
    44  pushd ../..
    45  clearmake lo
    46  pushd
    47  ls
    48  cleartool edcs
    49  cleartool ls cpt.c
    50  history

There are a number of ways of retrieving commands and parts of commands.

You can add on to a retrieved command by just sticking the new arguments after the recall operator:


% ls /vobs/Rm
[list of files]
% !!/bldtools
ls /vobs/Rm/bldtools
[different list of files]

If all you want to retrieve is a part of a command, there are a number of modifiers to select specific parts of a retrieved command line. They can be added on to all the methods above.

Substitution

There are two forms of substitution:


Tuesday Tiny Techie Tip -- 26 November 1996
Forward to (12/03/96)
Back to (11/19/96)
Written by Jeff Youngstrom

Up to the TTTT index

Tuesday Tiny Techie Tips are all © Copyright 1996-1997 by Jeff Youngstrom. Please ask permission before reproducing any of this material.