【发布时间】:2018-11-10 20:40:11
【问题描述】:
我目前正在尝试在一个输出如下内容的变量中找到一个字符串:
一二三
我的代码:
echo "please enter one,two or three)
read var
var1=one,two,threee
if [[ "$var" == $var1 ]]; then
echo "$var is in the list"
else
echo "$var is not in the list"
fi
编辑2:
我试过了,但还是不匹配。您认为它与先前答案中的确切字符串不匹配是正确的,因为它与部分匹配。
groups="$(aws iam list-groups --output text | awk '{print tolower($5)}' | sed '$!s/$/,/' | tr -d '\n')"
echo "please enter data"
read "var"
if [ ",${var}," = *",${groups},"* ]; then
echo "$var is in the list"
else
echo "$var is not in the list"
fi
尝试它仍然无法匹配我需要的确切字符串。
【问题讨论】:
-
这是什么语言?
-
bash 脚本 ...
-
你能添加一个标签'bash'吗?
-
my var1 是一个像我上面提到的那样运行和输出数据的命令。所以我将 $var 与 $var1 进行比较,但它从未成功找到我从 $var 中输入的任何字符串