如下:
read -p "need compile OEM installatoin package?yes/[no]" IS_OEM
if [[ -z $IS_OEM ]]
then
IS_OEM="No"
fi
if [[ "Yes" =~ $IS_OEM || "yes" =~ $IS_OEM ]]
then
echo $?
echo "Need compile OEM installatoin package!"
else
echo "Dont need compile OEM installatoin package!"
fi
need compile OEM installatoin package?yes/[no]y
need compile OEM installatoin package?yes/[no]Y
need compile OEM installatoin package?yes/[no]yes
need compile OEM installatoin package?yes/[no]Yes
都返回0,其它否返回1
“=~”
正则匹配,用来判断其左侧的参数是否符合右边的要求,如果匹配则为真(返回0),不匹配则为假(返回1)。
该博客主要介绍了Shell脚本中使用条件判断和正则表达式进行用户输入检查的示例。通过`read-p`读取用户输入,然后判断是否需要编译OEM安装包。当用户输入`yes`或`Yes`时,脚本返回0并提示需要编译,其他输入返回1并提示不需要编译。
480

被折叠的 条评论
为什么被折叠?



