#!/usr/bin/csh #################################### # File: if.csh # Name: Jen Chen # Updated on: 08/12/04 #################################### #Set the warning message if the user does not enter sufficient arguments on the #command line. set USAGE="if.csh argv[1] argv[2] ...; where argv[1], argv[2], ... are command line arguments." #Initialize the variable count to be 1. set count = 1 if($#argv < 1) then #DO NOT forget the "then" keyword on this line. echo "$USAGE" else while($count <= $#argv) #Note that $#argv means the total number of echo $argv[$count] #arguments passed from the command line. @ count = $count + 1 #All computation has to start with the @ sign end #in C-shell. endif #Remember to end your IF-statement with "endif". ################################## echo "Using if-then-else if-else-endif" set num = $argv[1] set num2 = $argv[2] if($num2 < $num) then echo "$num2" @ num2 = $num2 + 1 #Increment num2 by 1. else if($num2 > $num) then echo "$num2 is greater than $num" else echo "$num2 equals to $num" endif