调用可能有2个不同名称的程序

 翻版的袁城 发布于 2023-01-30 19:08

我正在尝试编写一个使用'get-iplayer'的脚本,并将用于不同的发行版.在debian上它位于'/ usr/bin/get-iplayer'中,但是在centos上,例如,它位于'/ usr/bin/get_iplayer'中.

我已经能够检查它是否安装 -

if [[ -f "/usr/bin/get-iplayer" ]] || [[ -f "/usr/bin/get_iplayer" ]]
then
    echo ;
else
    echo "$(tput setaf 1) $(tput setab 7) Error: 'get-iplayer' or 'get_iplayer' is not     installed. Please install it. $(tput sgr 0)"
fi

如果可以通过两个不同的名称知道,我怎么称它呢?

1 个回答
  • if [[ -x "/usr/bin/get-iplayer" ]]
    then player="/usr/bin/get-iplayer"
    elif [[ -x "/usr/bin/get_iplayer" ]]
    then player="/usr/bin/get_iplayer"
    else echo "$0: error: neither get-iplayer nor get_iplayer is installed in /usr/bin" >&2
         exit 1
    fi
    
    # Run it
    "$player" ...
    

    2023-01-30 19:10 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有