1. if/else 语句 语法: if condition; then commands;elif condition; then commands;else commands;fi 示例:需求:脚本需要1个参数才能正确运行,而在脚本执行时,如果指定的参数个数不等于1,则shell脚本就应该打印出一个错误信息,告知用户指定的参数个数不对,然后结束脚本的执行.#!/bin/bashif [ $# -ne 1 ];then echo "Error! Arguments are not correc…
在linux的shell中 if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句: if ... else ... fi 语句: if ... elif ... else ... fi 语句. 1) if ... else 语句 if ... else 语句的语法: if [ expression ] then Statement(s) to be executed if expression is true f…
条件测试 方式一:在Bash中 test命令和[]是等价的. test命令: if test $n1 -eq $n2 then echo "The two number are equal" fi []命令: "["后面和"]"前面有空格 if [ $n1 -eq $n2 ] then echo "The two number are equal" fi 方式二:(( expression )) 测试数学表达式结果 if ((…
原文链接:http://www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case).下面我将通过例子介绍下,各个语句使用方法. 一.shell条件语句(if用法) if语句结构[if/then/elif/else/fi] if 条件测试语句 then action [elif 条件 action else action…