09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>XENIX</strong> Programming csh: C Shell<br />

Using the argv Variable<br />

A csh command script can be interpreted by typing<br />

csh script [argument] ...<br />

where script is the name of the file containing a group of C shell commands and<br />

argument is a sequence of command arguments. The C shell places these arguments in<br />

the variable argv and then begins to read commands from script. These parameters are<br />

then available through the same mechanisms used to reference any other C shell<br />

variables.<br />

If you make the file script executable by typing<br />

or<br />

chmod 755 script<br />

chmod + x script<br />

and then place a C shell com ment at the beginning of the C shell script (i.e., begin the<br />

file with a number sign (#)), then /bin/csh will automatically be invoked to execute<br />

script when you type<br />

script<br />

If the file does not begin with a nu mber sign (#), then the C shell will call the standard<br />

shell /bin/sh to execute it. Thus from the C shell, you can execute scripts written for<br />

either the C shell or the standard shell. In the standard shell sh, you can only execute<br />

scripts written for sh and not scripts written for the C shell.<br />

Substituting Shell Variables<br />

After each input line is broken into words and history substitutions are done on it, the<br />

input line is parsed into distinct commands. Before each command is executed, a<br />

mechanism known as variable substitution is performed on these words. Keyed by the<br />

dollar sign ($), this substitution replaces the names of variables by their values. Thus<br />

echo $argv<br />

when placed in a command script, would cause the current value of the variable argv to<br />

be echoed to the output of the C shell script. It is an error for argv to be unset at this<br />

point.<br />

A number of notations are provided for accessing components and attributes of<br />

variables. The notation<br />

$?name<br />

expands to 1 if name is set or to 0 if name is not set. It is the fundamental mechanism<br />

used for checking whether particular variables have been assigned values. All other<br />

forms of reference to undefined variables cause errors.<br />

8-11

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!