Checking for installed packages and if not found install

前端 未结 4 383
野趣味
野趣味 2021-02-01 20:01

I need to check for installed packages and if not installed install them.

Example for RHEL, CentOS, Fedora:

rpm -qa | grep glibc-static
glibc-static-2.1         


        
4条回答
  •  日久生厌
    2021-02-01 20:29

    if [ $(yum list installed | cut -f1 -d" " | grep --extended '^full name of package being checked$' | wc -l) -eq 1 ]; then
      echo "installed";
    else
      echo "missing"
    fi
    

    I use this because it returns installed / missing without relying on an error state (which can cause problems in scripts taking a "no tolerance" approach to errors via

    set -o errexit
    

    for example)

提交回复
热议问题