今日では、この機能をユーザープログラムからも実行できるよう、 glob(3) というライブラリルーチンも存在している。
glob の規則を以下に述べる (POSIX.2 3.13)。
(ブラケット外部の) '?' はあらゆる単一の文字にマッチする。
(ブラケット外部の) '*' はあらゆる文字列にマッチする。 空文字列 (empty string) にもマッチする。
文字クラス (character class)
"[...]" と言う表記は、先頭の '[' に続く最初の文字が '!' で なければ、ブラケットの中に含まれている文字のどれか一つにマッチする。 ブラケットの内部に含まれる文字列は空であってはならない。 したがって ']' も最初の文字に指定すればブラケットの内部に含めることが できる (つまり"[][!]" は '[', ']', '!' の 3 文字のどれかにマッチする)。
領域指定 (range)
There is one special convention: two characters separated by '-' denote a range. (Thus, "[A-Fa-f0-9]" is equivalent to "[ABCDEFabcdef0123456789]".) One may include '-' in its literal meaning by making it the first or last character between the brackets. (Thus, "[]-]" matches just the two characters ']' and '-', and "[--0]" matches the three characters '-', '.', and '0', since '/' cannot be matched.)
補集合 (complementation)
An expression "[!...]" matches a single character, namely any character that is not matched by the expression obtained by removing the first '!' from it. (Thus, "[!]a-]" matches any single character except ']', 'a', and '-'.)
One can remove the special meaning of '?', '*', and '[' by preceding them by a backslash, or, in case this is part of a shell command line, enclosing them in quotes. Between brackets these characters stand for themselves. Thus, "[[?*\]" matches the four characters '[', '?', '*', and '\'.
'.' で始まるパス名では、この文字は陽にマッチさせなければならない。 (つまり rm * は .profile を削除しない。また tar c * ではすべてのファイルはアーカイブされない。 tar c . の方が良い。)
xv -wait 0 *.gif *.jpg
において、*.gif ファイルが全くない場合でも、 これは空のリストに展開されるため、エラーにならない。 しかし POSIX では、文法的に正しくないパターンや、 マッチがなかったパターンは、 そのまま変更されずに残されることになっている。 bash では、次のコマンドで昔からの振る舞いに設定することができる。
shopt -s nullglob
(同様の問題は別のところでも起こっている。例えば、古いスクリプトにおける
rm `find . -name "*~"`
のような記述は、新しいスクリプトでは
rm -f nosuchfile `find . -name "*~"`
のようにしなければならない。さもないと rm を引数リストなしで呼び出す可能性があり、 エラーメッセージが出てしまう。)
正規表現にもブラケット表現はあるが、否定は '^' でなされる。 POSIX ではワイルドカードパターンにおける "[^...]" を未定義であるとしている。
(iii) 領域指定 X-Y は X と Y に挟まれた (両端含む) すべての文字を意味する。 このとき、カレントロケール (current locale) の LC_COLLATE カテゴリーで定義されている照合順序が用いられる。
(iv) 名前付き文字クラス: 以下のようなものである。
[:alnum:] [:alpha:] [:blank:] [:cntrl:] [:digit:] [:graph:] [:lower:] [:print:] [:punct:] [:space:] [:upper:] [:xdigit:]
so that one can say "[[:lower:]]" instead of "[a-z]", and have things work in Denmark, too, where there are three letters past 'z' in the alphabet. These character classes are defined by the LC_CTYPE category in the current locale.
(v) Collating symbols, like "[.ch.]" or "[.a-acute.]", where the string between "[." and ".]" is a collating element defined for the current locale. Note that this may be a multicharacter element.
(vi) Equivalence class expressions, like "[=a=]", where the string between "[=" and "=]" is any collating element from its equivalence class, as defined for the current locale. For example, "[[=a=]]" might be equivalent to "[aáàäâ]", that is, to "[a[.a-acute.][.a-grave.][.a-umlaut.][.a-circumflex.]]".