<分区>
我目前正试图在一个输出如下内容的变量中找到一个字符串:
one,two,three
我的代码:
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
尝试这个仍然没有匹配我需要的确切字符串。