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 领生日祝福语 简短独特
18 18岁生日简短祝福语