1.\" $OpenBSD: glob.7,v 1.6 2019/01/25 00:19:26 millert Exp $ 2.\" 3.\" Copyright (c) 2009 Todd C. Miller <millert@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.\" 18.Dd $Mdocdate: January 25 2019 $ 19.Dt GLOB 7 20.Os 21.Sh NAME 22.Nm glob 23.Nd shell-style pattern matching 24.Sh DESCRIPTION 25Globbing characters 26.Pq wildcards 27are special characters used to perform pattern matching of pathnames and 28command arguments in the 29.Xr csh 1 , 30.Xr ksh 1 , 31and 32.Xr sh 1 33shells as well as 34the C library functions 35.Xr fnmatch 3 36and 37.Xr glob 3 . 38A glob pattern is a word containing one or more unquoted 39.Ql \&? 40or 41.Ql * 42characters, or 43.Dq [..] 44sequences. 45.Pp 46Globs should not be confused with the more powerful 47regular expressions used by programs such as 48.Xr grep 1 . 49While there is some overlap in the special characters used in regular 50expressions and globs, their meaning is different. 51.Pp 52The pattern elements have the following meaning: 53.Bl -tag -width Ds 54.It \&? 55Matches any single character. 56.It \&* 57Matches any sequence of zero or more characters. 58.It [..] 59Matches any of the characters inside the brackets. 60Ranges of characters can be specified by separating two characters by a 61.Ql - 62(e.g.\& 63.Dq [a0-9] 64matches the letter 65.Sq a 66or any digit). 67In order to represent itself, a 68.Ql - 69must either be quoted or the first or last character in the character list. 70Similarly, a 71.Ql \&] 72must be quoted or the first character in the list if it is to represent itself 73instead of the end of the list. 74Also, a 75.Ql \&! 76appearing at the start of the list has special meaning (see below), so to 77represent itself it must be quoted or appear later in the list. 78.Pp 79Within a bracket expression, the name of a 80.Em character class 81enclosed in 82.Sq [: 83and 84.Sq :] 85stands for the list of all characters belonging to that class. 86Supported character classes: 87.Bl -column "xdigit" "xdigit" "xdigit" -offset indent 88.It Li "alnum" Ta "cntrl" Ta "lower" Ta "space" 89.It Li "alpha" Ta "digit" Ta "print" Ta "upper" 90.It Li "blank" Ta "graph" Ta "punct" Ta "xdigit" 91.El 92.Pp 93These match characters using the macros specified in 94.Xr isalnum 3 , 95.Xr isalpha 3 , 96and so on. 97A character class may not be used as an endpoint of a range. 98.It [!..] 99Like [..], 100except it matches any character not inside the brackets. 101.It \e 102Matches the character following it verbatim. 103This is useful to quote the special characters 104.Ql \&? , 105.Ql \&* , 106.Ql \&[ , 107and 108.Ql \e 109such that they lose their special meaning. 110For example, the pattern 111.Dq \e\e\e\&*\e[x]\e\&? 112matches the string 113.Dq \e\&*[x]\&? . 114.El 115.Pp 116Note that when matching a pathname, the path separator 117.Ql / , 118is not matched by a 119.Ql \&? , 120or 121.Ql * , 122character or by a 123.Dq [..] 124sequence. 125Thus, 126.Pa /usr/*/*/X11 127would match 128.Pa /usr/X11R6/lib/X11 129and 130.Pa /usr/X11R6/include/X11 131while 132.Pa /usr/*/X11 133would not match either. 134Likewise, 135.Pa /usr/*/bin 136would match 137.Pa /usr/local/bin 138but not 139.Pa /usr/bin . 140.Sh SEE ALSO 141.Xr fnmatch 3 , 142.Xr glob 3 , 143.Xr re_format 7 144.Sh HISTORY 145In early versions of 146.Ux , 147the shell did not do pattern expansion itself. 148A dedicated program, 149.Pa /etc/glob , 150was used to perform the expansion and pass the results to a command. 151In 152.At v7 , 153with the introduction of the Bourne shell, 154this functionality was incorporated into the shell itself. 155