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 婆婆高寿祝福语大全简短