if
注意 || 的两边和中括号里的开始和结束都有空格
1 #!/bin/bash
2 read -p " please intput (Y/N): " value
3 if [ "$value" == "Y" ] || [ "$value" == "y" ]; then
4 echo "your input is Y"
5 exit 0
6 fi
7
8 if [ "$value" == "N" ] || [ "$value" == "n" ]; then
9 echo "your input is N"
10 exit 0
11 fi
12
if else
1 #!/bin/bash
2 read -p " please intput (Y/N): " value
3 if [ "$value" == "Y" ] || [ "$value" == "y" ]; then
4 echo "your input is Y"
5 exit 0
6 else
7 echo "your input is N"
8 exit 0
9 fi
if elif
1 #!/bin/bash
2 read -p " please intput (Y/N): " value
3 if [ "$value" == "Y" ] || [ "$value" == "y" ]; then
4 echo "your input is Y"
5 exit 0
6 elif [ "$value" == "N" ] || [ "$value" == "n" ];then
7 echo "your input is N"
8 exit 0
9 fi
case
1 #!/bin/bash
2
3 case $1 in
4 "a")
5 echo " param is: a "
6 ;;
7
8 "b")
9 echo " param is: b "
10 ;;
11
12 *)
13 echo "can't identify! "
14 ;;
15 esac
函数
1 #!/bin/bash
2
3 function help(){
4 echo "this is help cmd!"
5 }
6 function close(){
7 echo "this is close cmd! "
8 }
9
10 case $1 in
11 "-h")
12 help
13 ;;
14
15 "-c")
16 close
17 ;;
18 esac
函数传参
1 #!/bin/bash
2
3 function print(){
4 echo "param 1 $1"
5 echo "param 2 $2"
6 }
7
8 print a b
while循环
1 #!/bin/bash
2
3 while [ "$value" != "close" ]
4 do
5 read -p "please input str: " value
6 done
7
8 echo " stop while"
for循环
1 #!/bin/bash
2
3 for name in qsc1 qsc2 qsc3 qsc4
4 do
5 echo " your name $name "
6 done
1 #!/bin/bash
2
3 read -p "please input int count: " count
4
5 for ((i=0;i<=count;i=i+1))
6 do
7 echo " your num $i "
8 done