逻辑判断之if

1 if条件判断的格式
if [ 条件判断 ];then.....;fi
if [ 条件判断 ];then.....;else.....;fi
if [ 条件判断1 ];then.....;elsif [ 条件判断2 ].....;fi

shiyanlou:Desktop/ $ if [ -e brackets.desktop ];then echo "hello";fi            [22:34:04]
hello
shiyanlou:Desktop/ $ if [ -e brackets.desktop ];then echo file exit;else echo file not exit;fi
file exit

2 如果是简单的分支判断可以用&& ||替换if语句

file exit
shiyanlou:Desktop/ $ [ -e test.h ] && echo file exit || echo file not exit      [22:44:38]
file not exit
shiyanlou:Desktop/ $ 

你可能感兴趣的:(逻辑判断之if)