美文网首页
flow control: if, and the 'test

flow control: if, and the 'test

作者: cutelittlePanda | 来源:发表于2018-03-26 11:08 被阅读0次

    if [ commands/test expression ]; then

        commands

    elif [ commands /test expression ]; then

        commands

    else

        commands

    fi

    Test Expression in IF : is envaluated either true or false; if true, execute following commands, then exit 0; elif false, exit 1 directly, no any commands executed;

    1. String Test Expression

    string test expressions

    2. File Test Expression

    file test expressions Integer expressions

    Advanced Test

    1).  syntax [[  expression  ]] , this advanced test supports a new string expression:

        string1 =~ regex

    ### the string operator ' =~ ' means ' string1 matchs the regular expression regex';

    this '[[   ]]' still supports 'pattern matching' with operator '==', examples:

    Sting [[ ]]

    Advanced test for integer:  synx  ((   )), used to perform arithmetic truth test; it's Truth if the expression result is non-zero.

    a=1

    (( b = a + 1 )) 

    echo $b   ### 2

    相关文章

      网友评论

          本文标题:flow control: if, and the 'test

          本文链接:https://www.haomeiwen.com/subject/gyowqftx.html