如果在 Ubuntu 中,则使用 bash 文件检查已安装的应用程序
check for installed application using bash file if then in Ubuntu
我正在编写 bash 文件以在 Ubuntu 中使用 apt-get 安装应用程序,但我不知道如何检查应用程序是否已安装。
我想的伪代码是这样的:
string app_list = {list of applications}
for i in app_list {
if i exists = False {
apt-get install i
}
else {}
}
dpkg -l "package name"
if [ $? = '0' ]
then
printf "Package is installed"
elif [ $? = '1' ]
then
printf "package is not installed"
fi
当然,您需要根据自己的目的进行设置,但可以使用获取命令错误代码的一般思路来检查软件包的安装状态。
我正在编写 bash 文件以在 Ubuntu 中使用 apt-get 安装应用程序,但我不知道如何检查应用程序是否已安装。
我想的伪代码是这样的:
string app_list = {list of applications}
for i in app_list {
if i exists = False {
apt-get install i
}
else {}
}
dpkg -l "package name"
if [ $? = '0' ]
then
printf "Package is installed"
elif [ $? = '1' ]
then
printf "package is not installed"
fi
当然,您需要根据自己的目的进行设置,但可以使用获取命令错误代码的一般思路来检查软件包的安装状态。