Using logical OR (||) in C-Shell
I have a C-Shell code where I use the following command:
if($#arr == 0 || $arr[1] == "test1") then
It outputs an error message saying "tcsh: arr: Subscript out o开发者_如何学运维f range." obviously because the first condition is true. Is it possible to force it to ignore the second condition if the first condition is true?
csh parses the entire line and substitutes variables before evaluating the expression. so in this case, you'd need a nested if because the or condition does not implement short-circuit evaluation with respect to variables.
精彩评论