控制流结构

控制流结构

一.   退出状态

1.       $ echo $? 最后命令退出状态

2.       $$ || 控制次序命令

3.       exit n 退出当前进程

4.        

二.if 语句

    if condition   

if condition
                 then
command1 if condition is true or if exit status
of condition is 0 (zero)
...
...
fi

 

if...else...fi

If given condition is true then command1 is executed otherwise command2 is executed.
Syntax:

   	        if condition
       	    then
                       condition is zero (true - 0)
                       execute all commands up to else statement

	           else
                       if condition is not true then
                       execute all commands up to fi
         	  fi
 

if-then-else

Syntax:
           if condition
           then
                       condition is zero (true - 0)
                       execute all commands up to elif statement
           elif condition1 
then condition1 is zero (true - 0) execute all commands up to elif statement elif condition2 then condition2 is zero (true - 0) execute all commands up to elif statement else None of the above condtion,condtion1,condtion2 are true (i.e. all of the above nonzero or false) execute all commands up to fi fi

 

  

         if 条件

         then 命令

fi

         三.

         1.变量值测试

         2Gerp输出检查

         3.用变量检查grep输出

         4.文件拷贝输出检查

         5.当前目录测试

         6.文件权限测试:用if语句测试文件权限

         7.测试传递到脚本中的参数

                   $# 表示调用参数的个数

         四.Case语句

         Case in

         模式1}

                            命令1

                           

                            ;;

         模式2}

                            命令2

                           

;;

         Esac

         五.for

                  1.对for循环使用参数

                            for循环中省去in列表,它将接受命令行位置参数作为参数

                            for params in “$@”  for params in “$*”

                   2.      for循环嵌套使用

                            for 变量名1 in 列表1

                            do

                                     for 变量名2 in 列表2

                                     do 命令1

                                     done

                            done

         六.Until

                   Until 循环执行一系列命令直到条件为真时停止

                   格式

                   Until 条件

                   命令1

                   done

         七.While 循环

                   while 命令

                   do

                   命令1

                   命令2

                   done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值