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

     

  • 相关阅读:
    Codeforces 1381B Unmerge(序列划分+背包)
    daily overview(2020.03.07update:该网站打不开惹
    矩阵相关
    颓式子
    51nod 1603 限高二叉排列树/1412 AVL树的种类
    模板合集(未完
    【luogu5651】 基础最短路练习题 [?]
    一个大Za
    【2019.11.11】
    【noip2017】
  • 原文地址:https://www.cnblogs.com/blog4matto/p/5572022.html
Copyright © 2011-2022 走看看