1glob(n)                      Tcl Built-In Commands                     glob(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       glob - Return names of files that match patterns
9

SYNOPSIS

11       glob ?switches? pattern ?pattern ...?
12_________________________________________________________________
13
14

DESCRIPTION

16       This  command performs file name “globbing” in a fashion similar to the
17       csh shell.  It returns a list of the files whose names match any of the
18       pattern  arguments.   No particular order is guaranteed in the list, so
19       if a sorted list is required the caller should use lsort.
20
21       If the initial arguments to glob start with - then they are treated  as
22       switches.  The following switches are currently supported:
23
24       -directory directory
25              Search  for files which match the given patterns starting in the
26              given directory.  This allows  searching  of  directories  whose
27              name  contains  glob-sensitive  characters  without  the need to
28              quote such characters explicitly.  This option may not  be  used
29              in  conjunction with -path, which is used to allow searching for
30              complete file paths whose names may contain glob-sensitive char‐
31              acters.
32
33       -join  The  remaining pattern arguments are treated as a single pattern
34              obtained by joining the arguments with directory separators.
35
36       -nocomplain
37              Allows an empty list to be returned without error;  without this
38              switch an error is returned if the result list would be empty.
39
40       -path pathPrefix
41              Search for files with the given pathPrefix where the rest of the
42              name matches the given  patterns.   This  allows  searching  for
43              files with names similar to a given file (as opposed to a direc‐
44              tory) even when the  names  contain  glob-sensitive  characters.
45              This option may not be used in conjunction with -directory.  For
46              example, to find all files with the same root name as $path, but
47              differing  extensions,  you should use glob -path [file rootname
48              $path] .* which will work even if $path contains numerous  glob-
49              sensitive characters.
50
51       -tails Only  return  the part of each file found which follows the last
52              directory named in any -directory or -path  path  specification.
53              Thus  glob  -tails  -directory  $dir  * is equivalent to set pwd
54              [pwd] ; cd $dir ; glob *; cd $pwd.   For  -path  specifications,
55              the  returned  names will include the last path segment, so glob
56              -tails -path [file rootname ~/foo.tex]  .*   will  return  paths
57              like foo.aux foo.bib foo.tex etc.
58
59       -types typeList
60              Only  list  files or directories which match typeList, where the
61              items in the list have two forms.  The first form  is  like  the
62              -type option of the Unix find command: b (block special file), c
63              (character special file), d (directory), f (plain file), l (sym‐
64              bolic link), p (named pipe), or s (socket), where multiple types
65              may be specified in the list.  Glob will return all files  which
66              match at least one of the types given.  Note that symbolic links
67              will be returned both if -types l is given, or if the target  of
68              a  link  matches  the requested type.  So, a link to a directory
69              will be returned if -types d was specified.
70
71              The second form specifies types where all the types  given  must
72              match.   These  are  r,  w, x as file permissions, and readonly,
73              hidden as special permission cases.   On  the  Macintosh,  MacOS
74              types  and  creators are also supported, where any item which is
75              four characters long is assumed to be a MacOS type (e.g.  TEXT).
76              Items  which are of the form {macintosh type XXXX} or {macintosh
77              creator XXXX} will match types or creators respectively.  Unrec‐
78              ognized  types,  or  specifications of multiple MacOS types/cre‐
79              ators will signal an error.
80
81              The two forms may be mixed, so -types {d f r w}  will  find  all
82              regular  files OR directories that have both read AND write per‐
83              missions.  The following are equivalent:
84                            glob -type d *
85                            glob */
86              except that the first case doesn't return the trailing  “/”  and
87              is more platform independent.
88
89       --     Marks the end of switches.  The argument following this one will
90              be treated as a pattern even if it starts with a -.
91
92       The pattern arguments may contain any of the following special  charac‐
93       ters:
94
95       ?         Matches any single character.
96
97       *         Matches any sequence of zero or more characters.
98
99       [chars]   Matches  any  single character in chars.  If chars contains a
100                 sequence of the form a-b then any character between a  and  b
101                 (inclusive) will match.
102
103       \x        Matches the character x.
104
105       {a,b,...} Matches any of the strings a, b, etc.
106
107       On  Unix, as with csh, a “.”  at the beginning of a file's name or just
108       after a “/” must be matched explicitly or with a {}  construct,  unless
109       the  -types  hidden  flag  is  given  (since “.”  at the beginning of a
110       file's name indicates that it is hidden).  On  other  platforms,  files
111       beginning  with a “.”  are handled no differently to any others, except
112       the special directories “.”  and “..”  which must be matched explicitly
113       (this  is  to  avoid a recursive pattern like “glob -join * * * *” from
114       recursing up the directory hierarchy as well as down). In addition, all
115       “/” characters must be matched explicitly.
116
117       If  the  first character in a pattern is “~” then it refers to the home
118       directory for the user whose name follows the “~”.  If the “~” is  fol‐
119       lowed  immediately  by “/” then the value of the HOME environment vari‐
120       able is used.
121
122       The glob command differs from csh globbing in two ways.  First, it does
123       not  sort  its  result list (use the lsort command if you want the list
124       sorted).  Second, glob only returns the names of  files  that  actually
125       exist;  in csh no check for existence is made unless a pattern contains
126       a ?, *, or [] construct.
127
128       When the glob command returns relative paths whose filenames start with
129       a  tilde  “~”  (for example through glob * or glob -tails, the returned
130       list will not quote the tilde with “./”.  This means care must be taken
131       if those names are later to be used with file join, to avoid them being
132       interpreted as absolute paths pointing to a given  user's  home  direc‐
133       tory.
134

PORTABILITY ISSUES

136       Windows  For Windows UNC names, the servername and sharename components
137       of the path may not contain ?, *, or [] constructs.  On Windows NT,  if
138       pattern is of the form “~username@domain”, it refers to the home direc‐
139       tory of the user whose account information resides on the specified  NT
140       domain  server.   Otherwise,  user account information is obtained from
141       the local computer.  On Windows 95 and 98, glob accepts  patterns  like
142       “.../” and “..../” for successively higher up parent directories.
143
144       Since  the  backslash  character has a special meaning to the glob com‐
145       mand, glob patterns containing Windows style path separators need  spe‐
146       cial  care.  The pattern C:\\foo\\* is interpreted as C:\foo\* where \f
147       will match the single character f and \* will match the single  charac‐
148       ter * and will not be interpreted as a wildcard character. One solution
149       to this problem is to use the Unix style forward slash as a path  sepa‐
150       rator.  Windows  style  paths can be converted to Unix style paths with
151       the command file join $path (or file normalize $path in Tcl 8.4).
152

EXAMPLES

154       Find all the Tcl files in the current directory:
155              glob *.tcl
156
157       Find all the Tcl files in the user's home  directory,  irrespective  of
158       what the current directory is:
159              glob -directory ~ *.tcl
160
161       Find all subdirectories of the current directory:
162              glob -type d *
163
164       Find all files whose name contains an “a”, a “b” or the sequence “cde”:
165              glob -type f *{a,b,cde}*
166
167

SEE ALSO

169       file(n)
170
171

KEYWORDS

173       exist, file, glob, pattern
174
175
176
177Tcl                                   8.3                              glob(n)
Impressum