如何通过 Bash 脚本检查 Linux 中是否安装了 rar unrar?
问问题
1306 次
4 回答
2
如果你可以试试
type -P unrar >/dev/null && echo it\'s installed\!
当然,这只会检测到$PATH
,而不是系统上的任何地方。
于 2011-12-12T14:41:41.393 回答
2
#!/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
确保如果您使用条件语句,它会在丢失文件的情况下失败。
于 2011-12-12T14:46:44.273 回答
1
另一个解决方案:
$whereis rar
于 2011-12-12T20:09:20.333 回答
0
灵感来自 Michael Krelin——hacker 的帖子和 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."
于 2011-12-13T06:20:21.773 回答