Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以使用 Bash 来匹配一组字符
$ [[ a =~ [abc] ]]; echo $? 0
]但是,如果我想在集合中包含一个右方括号,它会失败
]
$ [[ a =~ [abc\]] ]]; echo $? 1 $ [[ a =~ [abc\\]] ]]; echo $? 1
从手册页regex(7):
regex(7)
To include a literal ']' in the list, make it the first character (fol- lowing a possible '^').
测试:
$ [[ "]" =~ []abc] ]]; echo $? 0