shell之判断语句结构

来源:互联网 发布:c语言经典实例 编辑:程序博客网 时间:2024/06/05 05:08

在shell中流程控制分为两类:一类是循环,一类是判断选择。

1、if判断结构

if expression;then

    command

fi

2、if/else判断结构

if expression;then

    command

else

    command

fi

3、if/elif/else

if expression;then

    command

else

     if expression;then

        command

    else

        comamnd

    fi

fi

另外一种简洁写法

if expression;then

    command

elif expression;then

  command

elif expression;then

  command

。。。。。。

fi

4、case判断结构

case var in

var1)command;

var2)command;

var3)command;

var4)command;

.。。。。。。

*)command;

esac