home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 15.3 Adding { } Operators to Korn (and Bourne) Shells Chapter 15
Wildcards
Next: 15.5 Matching All "Dot Files" with Wildcards
 

15.4 What if a Wildcard Doesn't Match?

I ran into a strange situation the other day. I was compiling a program that was core dumping (52.9 ) . At some point, I decided to delete the object files and the core file, and start over, so I gave the command:

% rm *.o core

It works as expected most of the time, except when no object files exist. (I don't remember why I did this, but it was probably by using !! (11.7 ) when I knew there weren't any .o 's around.) In this case, you get No match , and the core file is not deleted.

It turns out, for C shell users, that if none of the wildcards can be expanded, you get a No match error. It doesn't matter that there's a perfectly good match for other name(s). That's because, when csh can't match a wildcard, it aborts and prints an error - it won't run the command. If you create one .o file or remove the *.o from the command line, core will disappear happily.

On the other hand, if the Bourne shell can't match a wildcard, it just passes the unmatched wildcard and other filenames:

*.o core

to the command (in this case, to rm ) and lets the command decide what to do with it. So, with Bourne shell, what happens will depend on what your command does when it sees the literal characters *.o .

You can make csh act a lot like sh by using:

set nonomatch

- ML , JP


Previous: 15.3 Adding { } Operators to Korn (and Bourne) Shells UNIX Power Tools Next: 15.5 Matching All "Dot Files" with Wildcards
15.3 Adding { } Operators to Korn (and Bourne) Shells Book Index 15.5 Matching All "Dot Files" with Wildcards

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










??????????????@Mail.ru