开发者

Using logical OR (||) in C-Shell

开发者 https://www.devze.com 2022-12-14 18:53 出处:网络
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.\" obviou

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消