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 生日广州男生祝福语简短