我可以使用
Bash来匹配一组字符
$[[ a =~ [abc] ]]; echo $? 0
但是,如果我想要一个紧密的方括号]包含在集合中,它就会失败
$[[ a =~ [abc\]] ]]; echo $? 1 $[[ a =~ [abc\\]] ]]; echo $? 1
解决方法
从手册页正则表达式(7):
To include a literal ']' in the list,make it the first character (fol- lowing a possible '^').
测试:
$[[ "]" =~ []abc] ]]; echo $? 0