Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
IBM : developerWorks : Linux : Education - Tutorials
LPI certification 101 exam prep, Part 1
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
5. Introducing wildcards
  


Wildcard caveats page 9 of 11


Here are some caveats to watch out for when using wildcards. Since bash treats wildcard-related characters (?, [, ], *) specially, you need to take special care when typing in an argument to a command that contains these characters. For example, if you want to create a file that contains the string [fo]*, the following command may not do what you want:


$ echo [fo]* > /tmp/mynewfile.txt

If the pattern [fo]* matches any files in the current working directory, then you'll find the names of those files inside /tmp/mynewfile.txt rather than a literal [fo]* like you were expecting. The solution? Well, one approach is to surround your characters with single quotes, which tell bash to perform absolutely no wildcard expansion on them:


$ echo '[fo]*' > /tmp/mynewfile.txt

Main menuSection menuFeedbackPreviousNext
PrivacyLegalContact