shell 判断变量是否为0

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或者为某个具体的值

你可能感兴趣的:(LInux,数据库,mysql,服务器)