Rectangle square bracket

I can use Bash to match a character set

$ [[ a =~ [abc] ]]; echo $? 0 

However, if I want a square bracket to be included in the set ] , it fails

 $ [[ a =~ [abc\]] ]]; echo $? 1 $ [[ a =~ [abc\\]] ]]; echo $? 1 
+4
source share
1 answer

On the man regex(7) page:

 To include a literal ']' in the list, make it the first character (fol- lowing a possible '^'). 

Testing:

 $ [[ "]" =~ []abc] ]]; echo $? 0 
+9
source

All Articles