我想读取变量的数据,看看是否有任何逗号分隔的数据匹配。
类似的东西:
allowed_versions={v1.0,v1.1,v1.5,v2.3}
read -r -p 'Enter a version: ' version_inputted
if [[ "${version_inputted}" == "${allowed_versions}" ]]
then
echo 'That version is allowed.'
else
echo 'That version is NOT allowed.'
fi
因此,实际上,它看起来像:
Enter a version: v1.0
That version is allowed.
Enter a version: v9.6
That version is NOT allowed.
Enter a version: v1.5
That version is allowed.
Enter a version: asdflj';~!@ #$%^&*)_+=-<>,.?/~`\|}{][:"(
That version is NOT allowed.
在OSX El Capitan 10.11.6上使用bash 3.2.57(1)版本。
如果可能的话,我真的更喜欢对变量使用oneliner。 谢谢。