[Next] [Previous] [Up] [Top] [Contents]

9.9.1 Conditional if

9.9.1.2 Csh

if (condition) command

-or-

if (condition1) then

command list if condition1 is true

[else if (condition2) then

command list if condition2 is true]

[else

command list if condition1 is false]

endif

The if and then must be on the same line.

#!/bin/csh -f

if ( $#argv >= 2 ) then

echo $2

else if ( $#argv == 1 ) then

echo $1

else

echo No input

endif

Again, this script should respond differently depending upon whether I have zero, one or more arguments on the command line. First with no arguments:

% ./if.csh

No input

Now with one argument:

% ./if.csh one

one

And now with two arguments:

% ./if.csh one two

two


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]