zoukankan      html  css  js  c++  java
  • Linux Gvim shell if...else语句

    #if else语句,共分三种:if...fi ; if ...else ...fi ; if ...elif...else...fi
    #if else fi 语句语法
    #if [ expression ]
    #then
    #    Statement to be executed if expression is true
    #else
    #    Statement to be executed if expression is not true
    #fi
    #if elif else fi语句语法:哪一个expression为true就执行哪一个语句,如果全是false则执行else语句
    #if [ expression 1 ]
    #then
    #   Statement(s) to be executed if expression 1 is true
    #elif [ expression 2 ]
    #then
    #   Statement(s) to be executed if expression 2 is true
    #elif [ expression 3 ]
    #then
    #   Statement(s) to be executed if expression 3 is true
    #else
    #   Statement(s) to be executed if no expression is true
    #fi

     1 a=30
     2 b=20
     3 if [ $a == $b ]
     4 then
     5    echo "a is equal to b"
     6 elif [ $a -gt $b ]
     7 then
     8    echo "a is greater than b"
     9 elif [ $a -lt $b ]
    10 then
    11    echo "a is less than b"
    12 else
    13    echo "None of the condition met"
    14 fi

    #if else 语句也可以写成一行,以命令的方式运行,如下:

    1 if test $[ 2*3 ] -eq $[ 1+5 ] ;then echo "true" ; fi

    #if else 语句也经常与test命令结合使用
    #test命令用于检查某个条件是否成立与 []类似

    1 num1=$[2*3]
    2 num2=$[1+5]
    3 if test ${num1} -eq ${num2}
    4 then
    5     echo 'The two numbers are equal!'
    6 else
    7         echo 'The two numbers are not equal!'
    8 fi

     

  • 相关阅读:
    javascript事件列表解说
    如何在ASP.NET页面中嵌入WINFORM控件
    ASP.NET 刷新后如何保持网页的位置
    JS的event 对象
    imp导入数据到ORACLE遭遇ORA12899错误
    求鞍点
    全排列递归实现
    三点顺序
    NYoj 14会场安排问题
    strchr和strstr函数
  • 原文地址:https://www.cnblogs.com/blog4matto/p/5572022.html
Copyright © 2011-2022 走看看