< Day Day Up > |
When evaluating the command line, the shell uses metacharacters to abbreviate filenames or pathnames that match a certain set of characters . The filename substitution metacharacters listed in Table 9.4 are expanded into an alphabetically listed set of filenames. The process of expanding a metacharacter into filenames is also called globbing . Unlike the other shells , when the C shell cannot substitute a filename for the metacharacter it is supposed to represent, the shell reports No match . Table 9.4. Shell Metacharacters and Filename Substitution
The shell performs filename substitution by evaluating its metacharacters and replacing them with the appropriate letters or digits in a filename. 9.8.1 The AsteriskThe asterisk matches zero or more characters in a filename. Example 9.28.1 % ls a.c b.c abc ab3 file1 file2 file3 file4 file5 2 % echo * a.c b.c abc ab3 file1 file2 file3 file4 file5 3 % ls *.c a.c b.c 4 % rm z*p No match. EXPLANATION
9.8.2 The Question MarkThe question mark matches exactly one character in a filename. Example 9.29.1 % ls a.c b.c abc ab3 file1 file2 file3 file4 file5 2 % ls ??? abc ab3 3 % echo How are you? No match. 4 % echo How are you\? How are you? EXPLANATION
9.8.3 The Square BracketsThe square brackets match a filename for one character from a set or range of characters. Example 9.30.1 % ls a.c b.c abc ab3 file1 file2 file3 file4 file5 file10 file11 file12 2 % ls file[123] file1 file2 file3 3 % ls [A-Za-z][a-z][1-5] ab3 4 % ls file1[0-2] file10 file11 file12 EXPLANATION
9.8.4 The Curly BracesThe curly braces ( {} ) match for a character or string of characters in a filename. Example 9.31.1 % ls a.c b.c abc ab3 ab4 ab5 file1 file2 file3 file4 file5 foo faa fumble 2 % ls f{oo,aa,umble} foo faa fumble 3 % ls a{.c,c,b[3-5]} a.c ab3 ab4 ab5 EXPLANATION
9.8.5 Escaping MetacharactersThe backslash is used to escape the special meaning of a single character. The escaped character will represent itself. Example 9.32.1 % gotta light? No match. 2 % gotta light\? gotta: Command not found. EXPLANATION
9.8.6 Tilde ExpansionThe tilde character by itself expands to the full pathname of the user's home directory. When the tilde is prepended to a username, it expands to the full pathname of that user's home directory. When prepended to a path, it expands to the home directory and the rest of the pathname. Example 9.33.1 % echo ~ /home/jody/ellie 2 % cd ~/desktop/perlstuff % pwd /home/jody/ellie/desktop/perlstuff 3 % cd ~joe % pwd /home/bambi/joe EXPLANATION
9.8.7 Filename Completion: The filec VariableWhen running interactively, the C/TC shell provides a shortcut method for typing a filename or username. The built-in filec variable, when set, is used for what is called filename completion. If you type the first few significant characters of a file in the current working directory and press the Esc key, the shell fills in the rest of the filename, provided that there are not a number of other files beginning with the same characters. If you type Ctrl-D after the partial spelling of the file, the shell will print out a list of files that match those characters. The terminal beeps if there are multiple matches. If the list begins with a tilde, the shell attempts to expand that list to a username. Example 9.34.1 % set filec 2 % ls rum rumple rumplestilsken run2 3 % ls ru[ESC] [a] # terminal beeps 4 % ls rum^D rum rumple rumplestilsken 5 % ls rump[ESC] rumple 6 % echo ~ell[ESC] /home/jody/ellie EXPLANATION
9.8.8 Turning Off Metacharacters with noglobIf the noglob variable is set, filename substitution is turned off, meaning that all metacharacters represent themselves ; they are not used as wildcards. This can be useful when searching for patterns in programs like grep , sed , or awk , which may contain metacharacters that the shell may try to expand. Example 9.35.1 % set noglob 2 % echo * ?? [] ~ * ?? [] ~ EXPLANATION
|
< Day Day Up > |