shell字符串与整数比较与运算

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yueludanfeng/article/details/83002282
#!/bin/sh
#字符串比较(比较大小以及是否相等)
a=hello
b=hello
c=how
if [[ "$a" == "$b" ]];then  #注意对于字符串的相等比较,使用=或==都可以,二者是等价的
	echo 'same'
else
	echo not same
fi

if [[ "$a"!="$c" ]];then
	echo "a!=c"
fi


if [[ "$a" < "$c" ]];then
	echo "a<c"
fi

#整数比较
a=1
b=2
if(($a<=$b));then
	echo "a<=b"
fi

if((a<=b));then
	echo "a<=b"
fi

# 整数运算
d=$(($a+$b))
echo $d

c=$((a+b))
echo $c

# 整数运算
c=$((a+b))
echo $c

#浮点数运算
a=1.223
b=2.3
c=$(echo $a+$b|bc)
echo $c

猜你喜欢

转载自blog.csdn.net/yueludanfeng/article/details/83002282