glob.n
来自「tcl是工具命令语言」· N 代码 · 共 193 行
N
193 行
'\"'\" Copyright (c) 1993 The Regents of the University of California.'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: glob.n,v 1.12 2002/07/01 18:24:39 jenglish Exp $'\" .so man.macros.TH glob n 8.3 Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEglob \- Return names of files that match patterns.SH SYNOPSIS\fBglob \fR?\fIswitches\fR? \fIpattern \fR?\fIpattern ...\fR?.BE.SH DESCRIPTION.PPThis command performs file name ``globbing'' in a fashion similar tothe csh shell. It returns a list of the files whose names match anyof the \fIpattern\fR arguments..LPIf the initial arguments to \fBglob\fR start with \fB\-\fR thenthey are treated as switches. The following switches arecurrently supported:.VS 8.3.TP\fB\-directory\fR \fIdirectory\fRSearch for files which match the given patterns starting in the given\fIdirectory\fR. This allows searching of directories whose namecontains glob-sensitive characters without the need to quote suchcharacters explicitly. This option may not be used in conjunction with\fB\-path\fR, which is used to allow searching for complete file pathswhose names may contain glob-sensitive characters..TP\fB\-join\fRThe remaining pattern arguments are treated as a single patternobtained by joining the arguments with directory separators..VE 8.3.TP\fB\-nocomplain\fRAllows an empty list to be returned without error; without thisswitch an error is returned if the result list would be empty..VS 8.3.TP\fB\-path\fR \fIpathPrefix\fRSearch for files with the given \fIpathPrefix\fR where the rest of the namematches the given patterns. This allows searching for files with namessimilar to a given file (as opposed to a directory) even when the names contain glob-sensitive characters. This option may not be used in conjunction with\fB\-directory\fR. For example, to find all files with the same root nameas $path, but differing extensions, you should use \fBglob -path [file rootname $path] .*\fR which will work even if $path containsnumerous glob-sensitive characters..TP\fB\-tails\fROnly return the part of each file found which follows the last directorynamed in any \fB\-directory\fR or \fB\-path\fR path specification. Thus \fBglob -tails -directory $dir *\fR is equivalent to \fBset pwd [pwd] ; cd $dir ; glob *; cd $pwd\fR. For \fB\-path\fR specifications, the returned names will include the lastpath segment, so \fBglob -tails -path [file rootname ~/foo.tex] .*\fR will return paths like \fBfoo.aux foo.bib foo.tex\fR etc..TP\fB\-types\fR \fItypeList\fROnly list files or directories which match \fItypeList\fR, where the itemsin the list have two forms. The first form is like the \-type option ofthe Unix find command:\fIb\fR (block special file),\fIc\fR (character special file),\fId\fR (directory),\fIf\fR (plain file),\fIl\fR (symbolic link),\fIp\fR (named pipe),or \fIs\fR (socket), where multiple types may be specified in the list.\fBGlob\fR will return all files which match at least one of the types given..RS.PPThe second form specifies types where all the types given must match.These are \fIr\fR, \fIw\fR, \fIx\fR as file permissions, and\fIreadonly\fR, \fIhidden\fR as special permission cases. On theMacintosh, MacOS types and creators are also supported, where any itemwhich is four characters long is assumed to be a MacOS type(e.g. \fBTEXT\fR). Items which are of the form \fI{macintosh type XXXX}\fRor \fI{macintosh creator XXXX}\fR will match types or creatorsrespectively. Unrecognized types, or specifications of multiple MacOStypes/creators will signal an error..PPThe two forms may be mixed, so \fB\-types {d f r w}\fR will find allregular files OR directories that have both read AND write permissions.The following are equivalent:.RS.CS\fBglob \-type d *\fR\fBglob */\fR.CE.REexcept that the first case doesn't return the trailing ``/'' andis more platform independent..RE.VE 8.3.TP\fB\-\|\-\fRMarks the end of switches. The argument following this one willbe treated as a \fIpattern\fR even if it starts with a \fB\-\fR..PPThe \fIpattern\fR arguments may contain any of the followingspecial characters:.TP 10\fB?\fRMatches any single character..TP 10\fB*\fRMatches any sequence of zero or more characters..TP 10\fB[\fIchars\fB]\fRMatches any single character in \fIchars\fR. If \fIchars\fRcontains a sequence of the form \fIa\fB\-\fIb\fR then anycharacter between \fIa\fR and \fIb\fR (inclusive) will match..TP 10\fB\e\fIx\fRMatches the character \fIx\fR..TP 10\fB{\fIa\fB,\fIb\fB,\fI...\fR}Matches any of the strings \fIa\fR, \fIb\fR, etc..LPOn Unix, as with csh, a ``.'' at the beginning of a file's name or justafter a ``/'' must be matched explicitly or with a {} construct,unless the ``-types hidden'' flag is given (since ``.'' at the beginning of a file's name indicates that it is hidden). On other platforms,files beginning with a ``.'' are handled no differently to any others,except the special directories ``.'' and ``..'' which must be matchedexplicitly (this is to avoid a recursive pattern like ``glob -join * ** *'' from recursing up the directory hierarchy as well as down).In addition, all ``/'' characters must be matched explicitly..LPIf the first character in a \fIpattern\fR is ``~'' then it refersto the home directory for the user whose name follows the ``~''.If the ``~'' is followed immediately by ``/'' then the value ofthe HOME environment variable is used..LPThe \fBglob\fR command differs from csh globbing in two ways.First, it does not sort its result list (use the \fBlsort\fRcommand if you want the list sorted).Second, \fBglob\fR only returns the names of files that actuallyexist; in csh no check for existence is made unless a patterncontains a ?, *, or [] construct..SH "PORTABILITY ISSUES".PPUnlike other Tcl commands that will accept both network and nativestyle names (see the \fBfilename\fR manual entry for details on hownative and network names are specified), the \fBglob\fR command onlyaccepts native names. .TP\fBWindows\fR.For Windows UNC names, the servername and sharename components of the pathmay not contain ?, *, or [] constructs. On Windows NT, if \fIpattern\fR isof the form ``\fB~\fIusername\fB@\fIdomain\fR'' it refers to the homedirectory of the user whose account information resides on the specified NTdomain server. Otherwise, user account information is obtained fromthe local computer. On Windows 95 and 98, \fBglob\fR accepts patternslike ``.../'' and ``..../'' for successively higher up parent directories..Since the backslash character has a special meaning to the glob command, glob patterns containing Windows style path separators need special care. The pattern \fIC:\e\efoo\e\e*\fR is interpreted as \fIC:\efoo\e*\fR where \fI\ef\fR will match the single character \fIf\fR and \fI\e*\fR will match the single character \fI*\fR and will not be interpreted as a wildcard character. One solution to this problem is to use the Unix style forward slash as a path separator. Windows style paths can be converted to Unix style paths with the command \fBfilejoin $path\fR (or \fBfile normalize $path\fR in Tcl 8.4). .TP \fBMacintosh\fR . When using the options, \fB\-directory\fR, \fB\-join\fR or \fB\-path\fR, globassumes the directory separator for the entire pattern is the standard``:''. When not using these options, glob examines each pattern argumentand uses ``/'' unless the pattern contains a ``:''..SH "SEE ALSO"file(n).SH KEYWORDSexist, file, glob, pattern
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?