#!/bin/csh
@ cows = 4 - 3 + 1
echo $cows
This simple csh script when run produces \"0\" for output when I\'d expect \"2\".
~root:
Operator grouping. It's reading the operation as 4 - (3 + 1), as opposed to (4 - 3) + 1.
The + and - operators are right-associative in csh. This means that '4 - 3 + 1' is evaluated as '4 - (3 + 1)'.
While you are expecting the operators to be left associative, they are right associative in csh, so it's evaluated as 4-(3+1)
-
/ \
/ \
4 +
/ \
3 1