【问题标题】:How to check rar install or not in linux via Bash Script?如何通过 Bash 脚本在 linux 中检查 rar 安装与否?
【发布时间】:2012-01-18 13:05:36
【问题描述】:

如何通过 Bash 脚本检查 Linux 中是否安装了 rar unrar?

【问题讨论】:

    标签: bash rar


    【解决方案1】:

    如果可以试试

    type -P unrar >/dev/null && echo it\'s installed\!
    

    当然,这只会检测到$PATH,而不是系统上的任何地方。

    【讨论】:

    • "!"应该从代码中删除,或者另一种选择: type -P unrar > /dev/null && echo -e "unrar is installed\041"
    • @arnkore。你说得对。我认为报价会防范它。 (固定)
    • 这是我第一次看到没有引号的回声,看起来很奇怪。-_-
    • 语法高亮让它变得很奇怪 ;-)
    【解决方案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 确保如果您使用条件语句,它会在丢失文件的情况下失败。

    【讨论】:

      【解决方案3】:

      另一种解决方案:

      $whereis rar
      

      【讨论】:

        【解决方案4】:

        灵感来自 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."
        

        【讨论】:

        • 将比某些恐龙物种更古老的成语归因于python是不公平的。
        • ;-)))))) 不,我没那么老。
        • 我应该把你放在python之后吗?hmms
        • 你可以放心地忽略我,当然,如果我确实启发了你,这取决于你。只是不要让我进入 python。
        猜你喜欢
        • 1970-01-01
        • 2012-09-14
        • 2014-08-03
        • 1970-01-01
        • 2015-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多