[Shell] to check whether the package is installed

Check the packages are installed

#!/bin/bash
if rpm -q sysstat &>/dev/null; then
    echo "sysstat is already installed."
else
    echo "sysstat is not installed!"
fi

Description:

sysstat package is, we want to detect the
rpm is the package management tool, -q inquiry mode to use to query the package exists or not.
then as if the condition is true, execute the following command

Premium

#!/bin/bash
if rpm -q $@ &>/dev/null; then
    echo "$@ is already installed."
else
    echo "$@ is not installed!"
fi

Output:

image

Script change command

step:

[root@node1 shell]# ls
demo.sh
[root@node1 shell]# mv demo.sh demo && cp demo /bin
[root@node1 shell]# demo 
这是一个演示脚本

image

Note: The script in /binthe current directory, make sure the next custom commands and the command does not have the same name directory

Guess you like

Origin www.cnblogs.com/BabySermonizer/p/11456605.html