本文介绍了我们在C Shell脚本中是否有短路逻辑运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为C shell脚本的行为类似于C,并对逻辑运算符使用短路评估.
I thought C shell script will behave like C and use short circuit evaluation for logical operators.
if ((! -e $cache ) || ("`find $monitor -newer $cache`" != "")) then
...
endif
但是在if语句中,即使第一个条件为true,也要检查第二个条件,这会给我带来错误.
But in the if statement, even if the first condition is true, the second is checked giving me errors.
我们在C shell脚本中有短路逻辑或吗?
Do we have a short circuit logical OR in C shell script?
推荐答案
通常,&&
和 ||
都是短路的.考虑这样的事情:
Usually, &&
and ||
are short-circut. Consider something like this:
$ false && echo foo
$ true || echo foo
在两种情况下,都不会将foo扑灭.
In both cases, foo won't be put out.
但是,AFAIK不能像这样使用这种字符串比较,即使发生短路,csh仍会对整个内容进行语法检查.
But, AFAIK you cannot use this kind of string comparison like this, even if short-circuit, csh will still syntax-check the whole thing.
这篇关于我们在C Shell脚本中是否有短路逻辑运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!