ECN No Name Newsletter: September, 1989

The ECN No Name Newsletter is no longer being published. This is an archived issue.

[previous article] [next article]

Powerful C-Shell Commands

Stacey Clark

Do you use C-shell?

Do you use history commands?

Do you like to save keystrokes?

If you do, then you already know the time saving power of reissuing commands without retyping the whole command line; or altering a previously issued command line while only typing the changes! If you don't already use this convenient power, you might consider using C-shell. Type "chsh" to convert to the C- shell; then set up history in your .chsrc file by adding "set history=XX" where XX is the max number of commands kept in the history list (for example, "set history=22").

Once history is in place, UNIX keeps a running list of command lines you have issued this computing session. A history listing obtained by typing "history" might look like:

1 mail
2 date
3 cat myfile
4 nmt. -Tpsc -t -e -g -o1-22 myfile | lpr -Pka2 -n -hg

To re-execute the last command, type "!!" at the C-shell prompt. If the nmt command were not the immediately preceding one, you could reference it by typing "!nmt" (a unique pattern for C- shell to find) or "!4" (the number of the command in the history listing).

Sometimes, you will type a long command with a typographical error in it! Here are 2 ways to change a UNIX command in C- shell. For example, say you wanted to send a troff job to the ka2 Apple LaserWriter, and you wanted pages 1,2,3,...,11. You would use the option "-o1-11". If you made a typo and typed "- o1-22", you could abort the command with control-c before sending it and re-execute it with the corrections.

One example would be:

Original command line:

% nmt. -Tpsc -t -e -g -o1-22 myfile | lpr -Pka2 -n -h

Correction:

% ^22^11

Altered command line:

% nmt. -Tpsc -t -e -g -o1-11 myfile | lpr -Pka2 -n -hg

Another example would be:

Original command line:

% nmt. -Tpsc -t -e -g -o1-22 myfile | lpr -Pka2 -n -h

Correction:

% !!:s/22/11

Altered command line:

% nmt. -Tpsc -t -e -g -o1-11 myfile | lpr -Pka2 -n -hg

You can also make GLOBAL changes of the UNIX command, but you must be careful, since all occurrences will change! For example, if you did a global substitution of 1 for 2, you would also change the printer name (ka2 -> ka1)!!

Original command line:

 
% nmt. -Tpsc -t -e -g -o1-22 myfile | lpr -Pka2 -n -h

Correction:

% !!:gs/2/1

Altered command line:

% nmt. -Tpsc -t -e -g -o1-11 myfile | lpr -Pka1 -n -hg

The caret method (^) only works on the immediately preceding command. The substitution method (:s/old/new) can work on any referenced command.

If C-shell looks interesting and you want to find out more details, please attend the free UNIX seminar for instruction,

CSH (C-shell)

September 26, 1989 at 10:30am in CE1144


webmaster@ecn.purdue.edu
Last modified: Wednesday, 29-Oct-97 15:03:43 EST

[HTML Check] HTML