Pages

jeudi 16 février 2012

flow control in csh


1) 
-----if (expression) simple command
or :
if (expression) then
  ...
else
  ...
endif

2) The switch statement can replace several if ... then statements. For the string given in the switch statement's argument, commands following the casestatement with the matching pattern are executed until the endsw statement. These patterns may contain ? and * to match groups of characters or specific characters.
switch (string)
  case pattern1:
    commands...
    breaksw
  case pattern2:
    commands...
    breaksw
  default:
    commands...
    breaksw
endsw
3) The while statement will enter the loop only if the expression evaluates to true (or non-zero). Once within the loop, the commands within it will continue to execute until the expression evaluates to false (zero).
while (expression)
commands...
end
4) 
The foreach statement takes an array variable and places the contents of each array element into the loop variable for each iteration.
foreach variable (array variable or list)
...
end
The break statement breaks out of the current loop.
break
The continue command returns to the top of the current loop after testing the condition for the loop.
continue
The shift command without arguments will shift the variable, argv down by one element. In other words, argv[2] becomes argv[1] and so forth, withargv[1] being discarded. With an array variable argument, the shift command performs the same operation on the variable specified.
shift

shift variable

Conditional expressions

The expressions used in the while and if commands are similar to C language expressions, with these exceptions:
=~
If the right hand side matches a pattern, (i.e., similar to filename matching, with asterisks and question marks.) the condition is true.
!~
If the right hand side doesn't match a pattern, the condition is true.
-d $var
True if the file is a directory.
-e $var
True if the file exists.
-f $var
True if the file is a file. (I.e., not a directory)
-o $var
True if the file is owned by the user.
-r $var
True if the user has read access.
-w $var
True if the user has write access.
-x $var
True if the user has execute access.
-z $var
True if the file is zero-length.

Aucun commentaire:

Enregistrer un commentaire