bash字符串与多个正确值进行比较 [英] bash string compare to multiple correct values

查看:107
本文介绍了bash字符串与多个正确值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下bashscript:

i have the following piece of bashscript:

function get_cms {
    echo "input cms name"
    read cms
    cms=${cms,,}
    if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then
        get_cms
    fi
}

但是无论我输入什么(正确和错误的值),它都不会再调用该函数,因为我只想允许这3个输入之一. 我已经尝试过||与[ var != value ] or [ var != value1 ] or [ var != value1 ] 但没有任何效果. 有人可以指出我正确的方向吗?

But no matter what i input (correct and incorrect values) it never calls the function again, because I only want to allow 1 of those 3 inputs. I have tried it with || with [ var != value ] or [ var != value1 ] or [ var != value1 ] but nothing works. Can someone point me in the right direction?

推荐答案

而不是说:

if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then

说:

if [[ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]]; then

您可能还想参考有条件的构造.

这篇关于bash字符串与多个正确值进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆