六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 21|回复: 0

shell 比较判断

[复制链接]

升级  72.33%

125

主题

125

主题

125

主题

举人

Rank: 3Rank: 3

积分
417
 楼主| 发表于 2013-2-7 14:50:59 | 显示全部楼层 |阅读模式
引用自:
http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/abs-3.9.1_cn/html/comparison-ops.html
 
 
#! /bin/shvar1=20var2=21if [ $var1 -ne $var2 ];then  echo "1. -ne means NOT equal true"fixyz="11"if [ -n "$xyz" ];then  echo "2. -n means init true(MUST to use \"\")"fiif [ -z "$1" ];then  echo "3. -z means NOT command-line arguments true"fifile="/etc/mtab"if [ -e $file ];then  echo "4. -e means file exists true"fihome="/root"if [ -d $home ];then  echo "5. -d means dir exists true"fi[ "true" ] && [ "false" ] && [ 0 ] && [ 1 ] && [ -1 ] && echo "6. string and integer means true"  
二元比较操作符用来比较两个变量或数字. 注意整数比较与字符串比较的区别.
<div class="VARIABLELIST">整数比较
-eq
等于
if [ "$a" -eq "$b" ]
-ne不等于
if [ "$a" -ne "$b" ]
-gt大于
if [ "$a" -gt "$b" ]
-ge大于等于
if [ "$a" -ge "$b" ]
-lt小于
if [ "$a" -lt "$b" ]
-le小于等于
if [ "$a" -le "$b" ]
<小于(在双括号中使用)
(("$a" < "$b"))
<=小于等于(在双括号中使用)
(("$a" <= "$b"))
>大于(在双括号中使用)
(("$a" > "$b"))
>=大于等于(在双括号中使用)
(("$a" >= "$b"))
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表