Unfortunately, we must start with some boring, but important technical stuff. This will tell you how to run your script using the C-shell. The stages are to select the shell, give execute access to the script, and then actually invoke the script using one of three ways.
The first line of your script tells UNIX which shell you want to use. The following selects the C-shell.
#is actually the comment character. That’s UNIX for you. However, its presence alone starting the first line will normally be sufficient to run a script in the C shell.
Most of the examples in this document are script excerpts, and so do not include the
If you want to run your script by name or with an alias (see below), you must make your script executable like this
myscriptis your C-shell script. Remember that the
%is a convention for the shell prompt; you do not type it yourself. You can edit the script without having to make the file executable again.
Once your script has execute privilege, thereafter you can run it like this:
.) or better, the specific directory to your PATH environment variable.
The second method is to define an alias. An alias is a shorthand for a long command to save typing. So in fact this method is just a variant of executing a script by name.
myscriptto run your script. Now this alias only applies to your current process. Even child processes derived from the current process will not inherit the alias. The way to make an alias global, so each new C-shell process recognises the alias, is to define the alias in your
$HOME/.cshrcfile. This file in your login directory defines the ‘environment’ for each C-shell process.
Here is a simple
.cshrc file. It sets some global variables:
noclobber prevents accidentally overwriting
an existing file and
history sets the number of previous commands you can recall. It defines three
aliases. The first lets you browse through a directory listing. The second reformats the output from df
on Digital UNIX so that lines do not wrap. The third lists the largest 20 files in a directory. Finally
.cshrc runs the script
/star/etc/cshrc to define Starlink aliases (the source command is explained in
There are two methods. One is permanent; the other overrides an alias for a single command. To
remove an alias permanently use the unalias command. This accepts
*?[ ]wildcards to match the
To override an alias, precede the alias with backslash. So suppose you have an alias to prevent you accidently removing a file as shown below.
myfile, then you would have a line like
The final option is to source your script so that it runs in the current process. The benefit of this technique is that any aliases defined in the current process will be known to your script. For example,
myscript. Any aliases created in
myscriptwill be available to the current process, unlike invocation by name. To save typing you can define an alias to source a script. See the next section on package aliases for an example.
While convenient, the creation of aliases in your
.cshrc file does have a drawback: if you define many
aliases in the
.cshrc file, it will decelerate process activation. One way around that is to define a few
aliases that run other scripts, each of which in turn define many related aliases. Thus you only create
the definitions when they are required. This is how most Starlink packages define their commands.
Here is an example. Suppose you had a package or a set of related commands called COSMIC
installed in directory
/home/user2/dro/cosmic, you would first place the following line in your
/home/user2/dro/cosmic/cosmic.cshis run. This file might look like the following.