| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: glob.7,v 1.2 2011/01/19 00:21:19 uwe Exp $ | | 1 | .\" $NetBSD: glob.7,v 1.3 2011/01/19 00:33:10 uwe Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" $OpenBSD: glob.7,v 1.3 2009/12/26 15:24:54 schwarze Exp $ | | 3 | .\" $OpenBSD: glob.7,v 1.3 2009/12/26 15:24:54 schwarze Exp $ |
4 | .\" | | 4 | .\" |
5 | .\" Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> | | 5 | .\" Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com> |
6 | .\" | | 6 | .\" |
7 | .\" Permission to use, copy, modify, and distribute this software for any | | 7 | .\" Permission to use, copy, modify, and distribute this software for any |
8 | .\" purpose with or without fee is hereby granted, provided that the above | | 8 | .\" purpose with or without fee is hereby granted, provided that the above |
9 | .\" copyright notice and this permission notice appear in all copies. | | 9 | .\" copyright notice and this permission notice appear in all copies. |
10 | .\" | | 10 | .\" |
11 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | | 11 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
12 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | | 12 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
13 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | | 13 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
14 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | | 14 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| @@ -31,105 +31,106 @@ command arguments in the | | | @@ -31,105 +31,106 @@ command arguments in the |
31 | .Xr ksh 1 , | | 31 | .Xr ksh 1 , |
32 | and | | 32 | and |
33 | .Xr sh 1 | | 33 | .Xr sh 1 |
34 | shells as well as | | 34 | shells as well as |
35 | the C library functions | | 35 | the C library functions |
36 | .Xr fnmatch 3 | | 36 | .Xr fnmatch 3 |
37 | and | | 37 | and |
38 | .Xr glob 3 . | | 38 | .Xr glob 3 . |
39 | A glob pattern is a word containing one or more unquoted | | 39 | A glob pattern is a word containing one or more unquoted |
40 | .Ql \&? | | 40 | .Ql \&? |
41 | or | | 41 | or |
42 | .Ql * | | 42 | .Ql * |
43 | characters, or | | 43 | characters, or |
44 | .Dq [..] | | 44 | .Dq Li [..] |
45 | sequences. | | 45 | sequences. |
46 | .Pp | | 46 | .Pp |
47 | Globs should not be confused with the more powerful | | 47 | Globs should not be confused with the more powerful |
48 | regular expressions used by programs such as | | 48 | regular expressions used by programs such as |
49 | .Xr grep 1 . | | 49 | .Xr grep 1 . |
50 | While there is some overlap in the special characters used in regular | | 50 | While there is some overlap in the special characters used in regular |
51 | expressions and globs, their meaning is different. | | 51 | expressions and globs, their meaning is different. |
52 | .Pp | | 52 | .Pp |
53 | The pattern elements have the following meaning: | | 53 | The pattern elements have the following meaning: |
54 | .Bl -tag -width Ds | | 54 | .Bl -tag -width Ds |
55 | .It \&? | | 55 | .It Li \&? |
56 | Matches any single character. | | 56 | Matches any single character. |
57 | .It \&* | | 57 | .It Li \&* |
58 | Matches any sequence of zero or more characters. | | 58 | Matches any sequence of zero or more characters. |
59 | .It [..] | | 59 | .It Li [..] |
60 | Matches any of the characters inside the brackets. | | 60 | Matches any of the characters inside the brackets. |
61 | Ranges of characters can be specified by separating two characters by a | | 61 | Ranges of characters can be specified by separating two characters by a |
62 | .Ql - | | 62 | .Ql \- |
63 | (e.g.\& | | 63 | (e.g.\& |
64 | .Dq [a0-9] | | 64 | .Dq Li [a0-9] |
65 | matches the letter | | 65 | matches the letter |
66 | .Sq a | | 66 | .Sq a |
67 | or any digit). | | 67 | or any digit). |
68 | In order to represent itself, a | | 68 | In order to represent itself, a |
69 | .Ql - | | 69 | .Ql \- |
70 | must either be quoted or the first or last character in the character list. | | 70 | must either be quoted or the first or last character in the character list. |
71 | Similarly, a | | 71 | Similarly, a |
72 | .Ql \&] | | 72 | .Ql \&] |
73 | must be quoted or the first character in the list if it is to represent itself | | 73 | must be quoted or the first character in the list if it is to represent itself |
74 | instead of the end of the list. | | 74 | instead of the end of the list. |
75 | Also, a | | 75 | Also, a |
76 | .Ql \&! | | 76 | .Ql \&! |
77 | appearing at the start of the list has special meaning (see below), so to | | 77 | appearing at the start of the list has special meaning (see below), so to |
78 | represent itself it must be quoted or appear later in the list. | | 78 | represent itself it must be quoted or appear later in the list. |
79 | .Pp | | 79 | .Pp |
80 | Within a bracket expression, the name of a | | 80 | Within a bracket expression, the name of a |
81 | .Em character class | | 81 | .Em character class |
82 | enclosed in | | 82 | enclosed in |
83 | .Sq [: | | 83 | .Ql [: |
84 | and | | 84 | and |
85 | .Sq :] | | 85 | .Ql :] |
86 | stands for the list of all characters belonging to that class. | | 86 | stands for the list of all characters belonging to that class. |
87 | Supported character classes: | | 87 | Supported character classes: |
88 | .Bl -column ".Li xdigit" ".Li xdigit" ".Li xdigit" -offset indent | | 88 | .Bl -column ".Li xdigit" ".Li xdigit" ".Li xdigit" -offset indent |
89 | .It Li "alnum" Ta Li "cntrl" Ta Li "lower" Ta Li "space" | | 89 | .It Li "alnum" Ta Li "cntrl" Ta Li "lower" Ta Li "space" |
90 | .It Li "alpha" Ta Li "digit" Ta Li "print" Ta Li "upper" | | 90 | .It Li "alpha" Ta Li "digit" Ta Li "print" Ta Li "upper" |
91 | .It Li "blank" Ta Li "graph" Ta Li "punct" Ta Li "xdigit" | | 91 | .It Li "blank" Ta Li "graph" Ta Li "punct" Ta Li "xdigit" |
92 | .El | | 92 | .El |
93 | .Pp | | 93 | .Pp |
94 | These match characters using the macros specified in | | 94 | These match characters using the macros specified in |
95 | .Xr ctype 3 . | | 95 | .Xr ctype 3 . |
96 | A character class may not be used as an endpoint of a range. | | 96 | A character class may not be used as an endpoint of a range. |
97 | .It [!..] | | 97 | .It Li [!..] |
98 | Like [..], | | 98 | Like |
| | | 99 | .Li [..] , |
99 | except it matches any character not inside the brackets. | | 100 | except it matches any character not inside the brackets. |
100 | .It \e | | 101 | .It Li \e |
101 | Matches the character following it verbatim. | | 102 | Matches the character following it verbatim. |
102 | This is useful to quote the special characters | | 103 | This is useful to quote the special characters |
103 | .Ql \&? , | | 104 | .Ql \&? , |
104 | .Ql \&* , | | 105 | .Ql \&* , |
105 | .Ql \&[ , | | 106 | .Ql \&[ , |
106 | and | | 107 | and |
107 | .Ql \e | | 108 | .Ql \e |
108 | such that they lose their special meaning. | | 109 | such that they lose their special meaning. |
109 | For example, the pattern | | 110 | For example, the pattern |
110 | .Dq \e\e\e\&*\e[x]\e\&? | | 111 | .Dq Li \e\e\e\&*\e[x]\e\&? |
111 | matches the string | | 112 | matches the string |
112 | .Dq \e\&*[x]\&? . | | 113 | .Dq \e\&*[x]\&? . |
113 | .El | | 114 | .El |
114 | .Pp | | 115 | .Pp |
115 | Note that when matching a pathname, the path separator | | 116 | Note that when matching a pathname, the path separator |
116 | .Ql / , | | 117 | .Ql / , |
117 | is not matched by a | | 118 | is not matched by a |
118 | .Ql \&? , | | 119 | .Ql \&? , |
119 | or | | 120 | or |
120 | .Ql * , | | 121 | .Ql * , |
121 | character or by a | | 122 | character or by a |
122 | .Dq [..] | | 123 | .Dq Li [..] |
123 | sequence. | | 124 | sequence. |
124 | Thus, | | 125 | Thus, |
125 | .Pa /usr/*/*/X11 | | 126 | .Pa /usr/*/*/X11 |
126 | would match | | 127 | would match |
127 | .Pa /usr/X11R6/lib/X11 | | 128 | .Pa /usr/X11R6/lib/X11 |
128 | and | | 129 | and |
129 | .Pa /usr/X11R6/include/X11 | | 130 | .Pa /usr/X11R6/include/X11 |
130 | while | | 131 | while |
131 | .Pa /usr/*/X11 | | 132 | .Pa /usr/*/X11 |
132 | would not match either. | | 133 | would not match either. |
133 | Likewise, | | 134 | Likewise, |
134 | .Pa /usr/*/bin | | 135 | .Pa /usr/*/bin |
135 | would match | | 136 | would match |