tree_version="tree-1.7.0"
tree_install_count=$(rpm -qa | grep -i ${tree_version} | wc -l) 查看已经安装 tree-1.7.0 版本的数量
写法 1
if [ "${tree_install_count}" -eq 0 ]; then
echo "tree-1.7.0 not exist."
else
echo "tree-1.7.0 count = ${tree_install_count}."
fi
写法 2
if [ "${tree_install_count}" == "0" ]; then
echo "tree-1.7.0 not exist."
else
echo "tree-1.7.0 count = ${tree_install_count}."
fi
[Ref] shell中判断一个变量是否为0或者为某个具体的值
整数比较
-eq 等于
-ne 不等于
-gt 大于
-ge 大于等于
-lt 小于
-le 小于等于
< > <= >= 都需要使用双括号