Shell 入门教程二十:关系运算符的使用

有时候我们需要比较两个数字的大小关系,这时候就要用到关系运算符。关系运算符只支持数值运算,不支持字符运算。

#!/bin/bash
# author:陈树义
# site:www.chenshuyi.com

a=10
b=20

if [ $a -gt $b ]
then
   echo "a great than b"
else
   echo "a not great than b"
fi

上面输出:a not great than b

除了支持大于运算符,Shell 语言还支持下面这些关系运算符:

  • -eq:检测两个数是否相等,相等返回 true。
  • -ne:检测两个数是否不相等,相等返回 true。
  • -gt:检测左边的数是否大于右边的,如果是返回 true。
  • -lt:检测左边的数是否小于右边的,如果是返回 true。
  • -ge:检测左边的数是否大于等于右边的,如果是返回 true。
  • -le:检测左边的数是否小于等于右边的,如果是返回 true。

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...