The C-shell has some special forms of variable. We have seen some already: the $< for prompting, and how to specify array elements. The remainder largely concern command-line arguments. Here they are tabulated.
| Syntax | Meaning |
| ${0} | The name of the script being run |
| $?name | Returns 1 if the variable name is defined, or 0 if it is not defined |
| $n | The value of the n |
| $argv[n] | The value of the n |
| $#argv | The number of arguments passed to the script |
| $* | All the arguments supplied to the script |
| $$ | Process identification number (useful for making temporary files with unique names) |
Let's look at a few examples. Below is a script argex.csh.
#! /bin/csh
echo ${0}
echo "Number of arguments is $#argv"
echo $2
echo $argv[2-3]
echo $argv[$]
exit
Then we run it with four arguments.
% argex.csh "hello world" 42 3.14159 "(300:400,~100)"
argex.csh
Number of arguments is 4
42
42 3.14159
(300:400,~100)
Note that you must enclose any argument passed to a script that contains
a space or shell metacharacter in double quotes (").
You can see an example using $* to process a list of files
here. There are other examples of script
arguments in UNIX options.
C-shell Cookbook