1*0f2e4277Saisha.\" $OpenBSD: glob.7,v 1.8 2023/05/30 14:04:53 aisha Exp $ 2dcd8b013Smillert.\" 3bf198cc6Smillert.\" Copyright (c) 2009 Todd C. Miller <millert@openbsd.org> 4dcd8b013Smillert.\" 5dcd8b013Smillert.\" Permission to use, copy, modify, and distribute this software for any 6dcd8b013Smillert.\" purpose with or without fee is hereby granted, provided that the above 7dcd8b013Smillert.\" copyright notice and this permission notice appear in all copies. 8dcd8b013Smillert.\" 9dcd8b013Smillert.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10dcd8b013Smillert.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11dcd8b013Smillert.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12dcd8b013Smillert.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13dcd8b013Smillert.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14dcd8b013Smillert.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15dcd8b013Smillert.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16dcd8b013Smillert.\" 17dcd8b013Smillert.\" 18*0f2e4277Saisha.Dd $Mdocdate: May 30 2023 $ 19dcd8b013Smillert.Dt GLOB 7 20dcd8b013Smillert.Os 21dcd8b013Smillert.Sh NAME 22dcd8b013Smillert.Nm glob 23dcd8b013Smillert.Nd shell-style pattern matching 24dcd8b013Smillert.Sh DESCRIPTION 25dcd8b013SmillertGlobbing characters 26dcd8b013Smillert.Pq wildcards 27dcd8b013Smillertare special characters used to perform pattern matching of pathnames and 28dcd8b013Smillertcommand arguments in the 29dcd8b013Smillert.Xr csh 1 , 30dcd8b013Smillert.Xr ksh 1 , 31dcd8b013Smillertand 32dcd8b013Smillert.Xr sh 1 33dcd8b013Smillertshells as well as 34dcd8b013Smillertthe C library functions 35dcd8b013Smillert.Xr fnmatch 3 36dcd8b013Smillertand 37dcd8b013Smillert.Xr glob 3 . 38dcd8b013SmillertA glob pattern is a word containing one or more unquoted 39dcd8b013Smillert.Ql \&? 40dcd8b013Smillertor 41dcd8b013Smillert.Ql * 42dcd8b013Smillertcharacters, or 43dcd8b013Smillert.Dq [..] 44dcd8b013Smillertsequences. 45dcd8b013Smillert.Pp 46dcd8b013SmillertGlobs should not be confused with the more powerful 47dcd8b013Smillertregular expressions used by programs such as 48dcd8b013Smillert.Xr grep 1 . 49dcd8b013SmillertWhile there is some overlap in the special characters used in regular 50dcd8b013Smillertexpressions and globs, their meaning is different. 51dcd8b013Smillert.Pp 52dcd8b013SmillertThe pattern elements have the following meaning: 53dcd8b013Smillert.Bl -tag -width Ds 54dcd8b013Smillert.It \&? 55dcd8b013SmillertMatches any single character. 56dcd8b013Smillert.It \&* 57dcd8b013SmillertMatches any sequence of zero or more characters. 58dcd8b013Smillert.It [..] 59dcd8b013SmillertMatches any of the characters inside the brackets. 60dcd8b013SmillertRanges of characters can be specified by separating two characters by a 61dcd8b013Smillert.Ql - 62dcd8b013Smillert(e.g.\& 63dcd8b013Smillert.Dq [a0-9] 64dcd8b013Smillertmatches the letter 65dcd8b013Smillert.Sq a 66dcd8b013Smillertor any digit). 67dcd8b013SmillertIn order to represent itself, a 68dcd8b013Smillert.Ql - 69dcd8b013Smillertmust either be quoted or the first or last character in the character list. 70dcd8b013SmillertSimilarly, a 71dcd8b013Smillert.Ql \&] 72dcd8b013Smillertmust be quoted or the first character in the list if it is to represent itself 73dcd8b013Smillertinstead of the end of the list. 74dcd8b013SmillertAlso, a 75dcd8b013Smillert.Ql \&! 76dcd8b013Smillertappearing at the start of the list has special meaning (see below), so to 77dcd8b013Smillertrepresent itself it must be quoted or appear later in the list. 78dcd8b013Smillert.Pp 79dcd8b013SmillertWithin a bracket expression, the name of a 80dcd8b013Smillert.Em character class 81dcd8b013Smillertenclosed in 82dcd8b013Smillert.Sq [: 83dcd8b013Smillertand 84dcd8b013Smillert.Sq :] 85dcd8b013Smillertstands for the list of all characters belonging to that class. 86dcd8b013SmillertSupported character classes: 87dcd8b013Smillert.Bl -column "xdigit" "xdigit" "xdigit" -offset indent 88*0f2e4277Saisha.It Li "alnum" Ta Li "cntrl" Ta Li "lower" Ta Li "space" 89*0f2e4277Saisha.It Li "alpha" Ta Li "digit" Ta Li "print" Ta Li "upper" 90*0f2e4277Saisha.It Li "blank" Ta Li "graph" Ta Li "punct" Ta Li "xdigit" 91dcd8b013Smillert.El 92dcd8b013Smillert.Pp 9389d38d05SschwarzeThese match characters using the macros specified in 9489d38d05Sschwarze.Xr isalnum 3 , 9589d38d05Sschwarze.Xr isalpha 3 , 9689d38d05Sschwarzeand so on. 97dcd8b013SmillertA character class may not be used as an endpoint of a range. 98dcd8b013Smillert.It [!..] 99dcd8b013SmillertLike [..], 100dcd8b013Smillertexcept it matches any character not inside the brackets. 101d12e563eSschwarze.It \e 102d12e563eSschwarzeMatches the character following it verbatim. 103d12e563eSschwarzeThis is useful to quote the special characters 104d12e563eSschwarze.Ql \&? , 105d12e563eSschwarze.Ql \&* , 106d12e563eSschwarze.Ql \&[ , 107d12e563eSschwarzeand 108d12e563eSschwarze.Ql \e 109d12e563eSschwarzesuch that they lose their special meaning. 110d12e563eSschwarzeFor example, the pattern 111d12e563eSschwarze.Dq \e\e\e\&*\e[x]\e\&? 112d12e563eSschwarzematches the string 113d12e563eSschwarze.Dq \e\&*[x]\&? . 114dcd8b013Smillert.El 115dcd8b013Smillert.Pp 116dcd8b013SmillertNote that when matching a pathname, the path separator 117dcd8b013Smillert.Ql / , 118dcd8b013Smillertis not matched by a 119dcd8b013Smillert.Ql \&? , 120dcd8b013Smillertor 121dcd8b013Smillert.Ql * , 122dcd8b013Smillertcharacter or by a 123dcd8b013Smillert.Dq [..] 124dcd8b013Smillertsequence. 125dcd8b013SmillertThus, 126dcd8b013Smillert.Pa /usr/*/*/X11 127dcd8b013Smillertwould match 128dcd8b013Smillert.Pa /usr/X11R6/lib/X11 129dcd8b013Smillertand 130dcd8b013Smillert.Pa /usr/X11R6/include/X11 131dcd8b013Smillertwhile 132dcd8b013Smillert.Pa /usr/*/X11 133dcd8b013Smillertwould not match either. 134dcd8b013SmillertLikewise, 135dcd8b013Smillert.Pa /usr/*/bin 136dcd8b013Smillertwould match 137dcd8b013Smillert.Pa /usr/local/bin 138dcd8b013Smillertbut not 139dcd8b013Smillert.Pa /usr/bin . 140dcd8b013Smillert.Sh SEE ALSO 141dcd8b013Smillert.Xr fnmatch 3 , 142dcd8b013Smillert.Xr glob 3 , 143dcd8b013Smillert.Xr re_format 7 144dcd8b013Smillert.Sh HISTORY 145f942c791SschwarzeA stand-alone program, 146dcd8b013Smillert.Pa /etc/glob , 147f942c791Sschwarzefirst appeared in 148f942c791Sschwarze.At v1 . 149f942c791SschwarzeIn PWB/UNIX 1.0 this functionality was incorporated into the shell itself. 150