Intro to csh

Introduction to csh


Why use csh scripts?

The basic idea of scripting with the shell is that you have a set of commands, and perhaps some control statements, which make the shell do a series of commands. Basically there is no difference between a script and a program.

In particular, csh can be good for writing short scripts to run test sequences. The following quote motivates using scripts in this way [2]:

How to invoke a csh script?

There are three ways:

  1. Execute csh directly and then enter script commands interactively.

  2. Store a group of csh commands in the file 'myScript' and execute it using:
    % csh myScript ...
    

    where '...' is replaced by a sequence of arguments. The shell places these arguments in the variable argv and then begins to read commands from the script.

  3. Begin the script with the line
    #!/usr/bin/csh ...
    
    where '...' is again the arguments to the shell. The only argument we will mention here is -f which stops the shell script from sourcing your ~/.cshrc.

    You can then execute the file directly, assuming it has been granted "execute" permissons.

Comments

Variables

Command Line Arguments

Control Flow

File Enquiries

Tips

References

  1. Basic Scripting with the csh by NCSA
  2. "The Practice of Programming", by Brian W. Kernighan and Rob Pike
  3. An Introduction to the C shell by William Joy
  4. "The Berkeley UNIX Environment" 2nd edition by R. Nigel Horspool