我可以使用Bash来匹配一组字符
$ [[ a =~ [abc] ]]; echo $?
0
但是,如果我希望将近方括号]
包含在集合中,则会失败
$ [[ a =~ [abc\]] ]]; echo $?
1
$ [[ a =~ [abc\\]] ]]; echo $?
1
答案 0 :(得分:9)
从手册页regex(7)
:
To include a literal ']' in the list, make it the first character (fol-
lowing a possible '^').
测试:
$ [[ "]" =~ []abc] ]]; echo $?
0