我写了下面的脚本,因为我试图帮助用户安装他们需要从一个yum仓库包。
该脚本的用法是./script PACKAGE VERSION
,
# !/bin/sh
PAKAGENAME=${1}
VERSION=${2}
if [[ -z ${1} ]]; then
echo "you should at least specify a component name"
echo "Usage : installrpm {COMPONENT} {VERSION}"
elif [[ -z ${2} ]]; then
echo "the latest version of the component will be installed"
sudo yum install -y ${1}
elif [[ ${1} == all ]]; then
echo "All component will be installed in latest versions available"
sudo yum remove -y PAKAGE1
sudo yum install -y PAKAGE1 --skip-broken
sudo yum remove -y PAKAGE2
sudo yum install -y PAKAGE2 --skip-broken
else
sudo yum remove -y ${1}
sudo yum install -y ${1}-${2}
fi
当我使用./script packagename version
或./script packagename
时,它可以工作,但当我尝试使用./script packagename all
时,我得到以下错误:
the latest deployed version of the component will be installed
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
No package all available.
Error: Nothing to do
看起来脚本开始寻找一个包名all
,即使我在这种情况下指定包。
我如何才能修复这个错误,我将感谢任何增强的脚本。
1条答案
按热度按时间klsxnrf11#
我认为问题在于第二个
elif
。您正在检查第一个opt(${1}
)是否等于all
,但在命令./script packagename all
中,optall
是第二个参数。因此,您可以尝试修改脚本,如下所示: