Shell脚本if else语句小结
和Java、PHP等语言不一样,sh的流程控制不可为空,如:
<?php
if(isset($_GET["q"])){
search(q);
}
else{
//donothing
}
?>
在sh/bash里可不能这么写,如果else分支没有语句执行,就不要写这个else,就像这样:
ifcondition then command1 command2 ... commandN fi
当然,也可以写成一行(适用于终端命令提示符),像这样:
iftest$[2*3]-eq$[1+5];thenecho'Thetwonumbersareequal!';fi;
末尾的fi就是if倒过来拼写,后面还会遇到类似的。
ifelse格式
ifcondition then command1 command2 ... commandN else command fi
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短