This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15828|Reply: 0

[linux] How to determine whether a command exists in Shell (Bash).

[Copy link]
Posted on 11/2/2021 11:17:19 AM | | |
Linux to view installed software (determine that the software is installed)

It's often a case of trying to tell if a software is already installed, but often RPM -qa | appears gerp name is not found
There are two ways to determine whether to install or not

rpm package installed, you can see it with rpm -qa, if you want to find out whether a package is installed, use rpm -qa | grep "the name of the software or package".
deb package installed, which can be seen with dpkg -l. If you are looking for a specified package, use dpkg -l | grep "the name of the software or package";
yum method installed, you can use yum list installed to find it, if it is to find the specified package, add | after the command grep "software name or package name";
For example:


Use which to determine if the brew command exists

which will output "xxx not found" to stderr when the command cannot be found.

It is best to avoid using which, as an external tool, it does not necessarily exist, and there will be differences between distributions, and some systems will not set a valid exit status, and there is a certain degree of uncertainty.

Bash provides some built-in commands such as hash, type, and command to meet the requirements.


Original:The hyperlink login is visible.





Previous:Jenkins (5) Project group presentation
Next:Linux (CentOS) ulimits server performance tuning
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com