我想在一行中使用rpm
命令检查是否安装了特定的Linux软件包。然而,作为目前的服务,它总是给我一个积极的结果,即使没有安装httpd
,你能在这里指出问题吗?
rpm -qa httpd && echo "service present" || echo " service not present"
通过替换<PACKAGE_NAME>
使用以下内容
更短
rpm -q <PACKAGE_NAME> && echo "service present" || echo "service not present"
更长
rpm -qa <PACKAGE_NAME> | grep <PACKAGE_NAME> && echo "service present" || echo "service not present"
示例:
rpm -qa httpd | grep httpd && echo "service present" || echo "service not present"
# Output
[root@bfa3155b8feb /]# rpm -qa httpd | grep httpd && echo "service present" || echo "service not present"
service not present