shall脚本

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值