What does [...] mean in a bash script?

I am reading this tutorial and I came across the fact that the bash script uses [...] as a wild card symbol. So what exactly is [...] in the bash script?

+3
source share
3 answers

This is the regex-style character matching syntax; from the Bash Reference Guide , Β§3.5.8.1 (pattern matching) :

[...]   Matches any of the enclosed characters. A pair of characters separated by a hyphen denotes a range expression; any character that sorts between the two characters inclusive, using the current locale matching sequence and character set, is mapped. If the first character following β€˜[’is is β€˜!’or β€˜^’, then any character is not attached. A β€˜βˆ’β€™can be matched by including it as the first or last character in the set. A β€˜]’can be matched by including it as the first character in the set. The sort order of characters in range expressions is determined by the current locale and the value of the shell variable LC_COLLATE, if one is set.

, C β€˜[a-dx-z]’ '[abcdxyz]. , β€˜[a-dx-z]’ β€˜[abcdxyz]’; , , β€˜[aBbCcDdxXyYz]’. , C, LC_COLLATE LC_ALL β€˜C’.

β€˜[’ β€˜]’ [:class:], class , posix:

          alnum   alpha   ascii   blank   cntrl   digit   graph   lower
          print   punct   space   upper   word    xdigit

, . , β€˜_’.

β€˜[’ β€˜]’ [=c=], ( ) c.

β€˜[’ β€˜]’ [.symbol.] .

( )

+6

globbing ('*' '?'). , [a-z] .

+5

In fact, that is the wildcard character, for example [abc]. It matches one of three letters.

+1
source

Source: https://habr.com/ru/post/1788956/


All Articles