In csh, why does 4 - 3 + 1 == 0?

前端 未结 3 835
猫巷女王i
猫巷女王i 2021-01-17 11:11
#!/bin/csh

@ cows = 4 - 3 + 1
echo $cows

This simple csh script when run produces \"0\" for output when I\'d expect \"2\".

~root:          


        
3条回答
  •  我在风中等你
    2021-01-17 11:35

    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
    

提交回复
热议问题