2

在 CSH 中,是否可以在同一个 if 子句中嵌套对变量是否存在的测试及其值的测试?

#!/bin/csh

# This seems to work...
if ( $?VAR ) then
    echo "VAR exists"        
    if ( $VAR == true ) then
        echo "VAR is true"
    endif
endif

# I want something more like this:
if (( $?VAR ) && ( $VAR == true )) then
    echo "VAR exists and is true"
endif
4

1 回答 1

2

短路评估是C shell 不做的许多事情之一。您将不得不使用嵌套if语句或切换 shell。

于 2010-10-26T00:18:47.677 回答