1.字符串相等比较
str1="abc"
str2="efg"
if [ "$str1"x == "$str2"x ]
then
echo "str1 == str2"
else
echo "str1 != str2"
fi
2.数字比较
a=1
b=1
if [ "$a" == "$b" ]
then
echo "a1 == b"
else
echo "a != b"
fi
/* -------------------------------------------
-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"))
------------------------------------------- */
一个配无损的小demo
#!/bin/bash
mode_name="RoCE v2"
for mlx_dev in $(ibdev2netdev | awk '{print $1}')
do
if_dev=$(ibdev2netdev | grep $mlx_dev | awk '{print $5}')
echo "------------> Current: ${mlx_dev}:${if_dev}"
mode=$(cma_roce_mode -d "${mlx_dev}" -p 1)
if [ "$mode"x = "$mode_name"x ]
then
cma_roce_mode -d "${mlx_dev}" -p 1 -m 2
cma_roce_tos -d "${mlx_dev}" -t 160
mlnx_qos -i "${if_dev}" --pfc 0,0,0,0,0,1,0,0 --trust dscp
echo 6 > /sys/class/net/${if_dev}/ecn/roce_np/cnp_802p_prio
sysctl -w net.ipv4.tcp_ecn=1
fi
done