Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 9.3 Reprinting Your Command Line with CTRL-r Chapter 9
Saving Time on the Command Line
Next: 9.5 Build Strings with { }

9.4 Use Wildcards to Create Files?

The shells' [] (square bracket) wildcards will match a range of files. For instance, if you have files named afile, bfile, cfile, and dfile, you can print the first three by typing:

% lpr [a-c]file

Now, let's say that you want to create some more files called efile, ffile, gfile, and hfile. What's wrong with typing the command line below? Try it. Instead of vi, you can use your favorite editor or the touch (21.7) command:

% vi [e-h]file   Doesn't make those four files
% ls
afile   bfile   cfile   dfile

Stumped? Take a look at article 1.16 about wildcard matching.

The answer: wildcards can't match names that don't exist yet. That's especially true with a command like touch ?file (21.7) or touch *file-think how many filenames those wildcards could possibly create!

Article 9.5 explains shell { } operators that solve this problem.

- JP

Previous: 9.3 Reprinting Your Command Line with CTRL-r UNIX Power ToolsNext: 9.5 Build Strings with { }
9.3 Reprinting Your Command Line with CTRL-r Book Index9.5 Build Strings with { }

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System