#!/bin/sh
date1=`date +%H "-d -10 hour"`
echo $date1
date2=`date +%H "-d -10 hour"`
if [ $date1 -eq $date2 ]
then
echo "yes"
date1=$((date1+1)) #不是02 而是 2
echo $date1
date2=`date +%H "-d -9 hour"`
echo $date2
if [ $date1 -eq $date2 ];then #比较数值 02 2 相等的
echo '=='
fi
if [ $date1 == $date2 ];then #比较字符串 02 2 不等的
echo "ok"
fi
fi
[hadoop@storm144 kafka_wangbin]$ ./datetest.sh
01
yes
2
02
==
shell编程中,-eq 用于整数的比较,=用于字符串的比较。
例如:
1
2
3
4
5
6
7
8
9
|
a=3
if
[ $a -
eq
3 ];
then
echo
"ok1"
fi
b=
"test"
if
[
"$b"
=
"test"
];
then
echo
"ok2"
fi
|
linux 中 没有== 但是在 [] 中 == 和 = 是等效的