6.1.2 case语句
(1)基本语法
case 变量 in
值1)  语句1
    ;;
值2)  语句2
    ;;
值3)  语句3
    ;;
esac
(2)案例
[root@iZ1608aqb7ntn9Z shellTest]# vim case.sh
#####################写入内容##############################
#!/bin/bash
  
i=$1
case $i in
1) echo "print one"
        ;;
2) echo "print two"
        ;;
3) echo "print three"
        ;;
esac
#####################写入内容结束##########################
[root@iZ1608aqb7ntn9Z shellTest]# ./case.sh 1
print one
[root@iZ1608aqb7ntn9Z shellTest]# ./case.sh 2
print two
[root@iZ1608aqb7ntn9Z shellTest]# ./case.sh 3
print three
6.2 循环语句 6.2.1 for循环
(1)基本语法
for 变量 in 变量1 变量2 ......
do
     语句
done
(2)案例
[root@iZ1608aqb7ntn9Z shellTest]# vim for.sh 
#####################写入内容##############################
#/bin/bash
  
for val in 1 2 3 4 5
do
        echo $val
done
#####################写入内容结束##########################
[root@iZ1608aqb7ntn9Z shellTest]# ./for.sh 
1
2
3
4
5
6.2.2 while循环
(1)基本语法
while(( 表达式 ))
do 
    语句
done
或者 
while true 
do
    语句
done
(2)案例
[root@iZ1608aqb7ntn9Z shellTest]# vim while.sh 
#!/bin/bash
  
i=1
while(( $i<=3 ))
do
        echo $i
        let "i++"
done
[root@iZ1608aqb7ntn9Z shellTest]# ./while.sh 
1
2
3
来源:【九爱网址导航www.fuzhukm.com】 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
 
  
  
  
  
 