码迷,mamicode.com
首页 > 系统相关 > 详细

Linux Gvim shell if...else语句

时间:2016-06-09 11:00:58      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:

#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

 

 

Linux Gvim shell if...else语句

标签:

原文地址:http://www.cnblogs.com/blog4matto/p/5572022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!