【发布时间】:2012-01-18 13:05:36
【问题描述】:
如何通过 Bash 脚本检查 Linux 中是否安装了 rar unrar?
【问题讨论】:
如何通过 Bash 脚本检查 Linux 中是否安装了 rar unrar?
【问题讨论】:
如果可以试试
type -P unrar >/dev/null && echo it\'s installed\!
当然,这只会检测到$PATH,而不是系统上的任何地方。
【讨论】:
#!/bin/bash
missing() {
echo $1 is missing 1>&2
return 127
}
RAR=`type -P rar || echo missing rar`
UNRAR=`type -P unrar|| echo missing unrar`
在您的脚本中使用 $RAR 或 $UNRAR... 来做任何事情。如果它们丢失,则脚本将回显该命令丢失
return 127 确保如果您使用条件语句,它会在丢失文件的情况下失败。
【讨论】:
另一种解决方案:
$whereis rar
【讨论】:
灵感来自 Michael Krelin - 黑客的帖子和 python 的 and-or 表达式,您只需输入以下内容:
type -P rar > /dev/null && echo "rar is installed." || echo "rar is not installed."
type -P unrar > /dev/null && echo "unrar is installed." || echo "unrar is not installed."
【讨论】: