Linux 中如果想要判断某个软件是否安装过,可以使用 command 命令



使用

1
$ command -pvV command [arg ...]

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ command -v java
/usr/bin/java

$ command -V java
java is /usr/bin/java

$ command -p java

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
-zero to select the "zero" VM
-dcevm to select the "dcevm" VM
The default VM is server.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
...

判断是否安装

1
2
3
if [ `command -v java` ];then
echo 'java 已经安装'
fi
03-16 19:20