075_扩展篇_Shell编程(六)_流程控制(二)_if多分支 实例1 脚本 #!/bin/bash if [ "$1"s = "abc"s ] then echo "OK" fi # 输入第二个参数,表示年龄,判断属于哪个年龄段 if [ $2 -lt 18 ] then echo "未成年" else echo "成年" fi 执行 [root@hadoop100 tf]# ./test_if2.sh abc 18 OK 成年 [root@hadoop100 tf]# ./test_if2.sh abc 8 OK 未成年 实例2 脚本 #!/bin/bash if [ "$1"s = "abc"s ] then echo "OK" fi # 输入第二个参数,表示年龄,判断属于哪个年龄段 if [ $2 -lt 18 ] then echo "未成年" elif [ $2 -lt 35 ] then echo "青年" elif [ $2 -lt 60 ] then echo "中年" else echo "老年" fi 执行 [root@hadoop100 tf]# ./test_if3.sh abc 5 OK 未成年 [root@hadoop100 tf]# ./test_if3.sh abc 25 OK 青年 [root@hadoop100 tf]# ./test_if3.sh abc 45 OK 中年 [root@hadoop100 tf]# ./test_if3.sh abc 65 OK 老年