如果第一个条件 return false,为什么在 csh 的逻辑 AND 操作中检查两个条件
Why both condition are checked in logical AND operation in csh if first condition return false
#!/bin/csh
set i=0
if ($i == 1 && { -e $HOME_EXIST } )then
echo "Hi"
else
echo "Hello"
endif
如果第一个条件 return 为假,为什么在 csh 的逻辑与运算中检查两个条件?
我收到以下错误:
HOME_EXIST: Undefined variable.
您的问题是即使 && 是惰性的,csh 也会在开始计算表达式 Reference 之前尝试替换 $HOME_EXIST。
您可以通过使用嵌套 ifs 来解决这个问题。
#!/bin/csh
set i=0
if ($i == 1)then
if(-e $HOME_EXIST)then
echo "Hi"
endif
else
echo "Hello"
endif
使用$?
检查变量是否定义:
if ($?HOME_EXIST) then
(do whatever you want)
endif
#!/bin/csh
set i=0
if ($i == 1 && { -e $HOME_EXIST } )then
echo "Hi"
else
echo "Hello"
endif
如果第一个条件 return 为假,为什么在 csh 的逻辑与运算中检查两个条件?
我收到以下错误:
HOME_EXIST: Undefined variable.
您的问题是即使 && 是惰性的,csh 也会在开始计算表达式 Reference 之前尝试替换 $HOME_EXIST。 您可以通过使用嵌套 ifs 来解决这个问题。
#!/bin/csh
set i=0
if ($i == 1)then
if(-e $HOME_EXIST)then
echo "Hi"
endif
else
echo "Hello"
endif
使用$?
检查变量是否定义:
if ($?HOME_EXIST) then
(do whatever you want)
endif