home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Tools / nShell™ 1.0.3 / nShell / User's Guide / 06 Wildcards < prev    next >
Encoding:
Text File  |  1994-08-17  |  2.5 KB  |  91 lines  |  [TEXT/ttxt]

  1. 06 Wildcards
  2. ============
  3.  
  4. Wildcards may be used to specify a set of files on the command line:
  5.  
  6.     % ls *.txt
  7.     jim.txt
  8.     bob.txt
  9.     %
  10.  
  11. In a shell environment wildcards are expanded on the command line, rather than within each command.  This means that expanded filenames are treated as text:
  12.  
  13.     % echo "These are my text files:" *.txt
  14.     These are my text files: jim.txt bob.txt
  15.     %
  16.  
  17. Wildcards may be matched within the current working directory or at the end of a pathname.  Matching in the middle of a pathname is not supported:
  18.  
  19. Good wildcard patterns:
  20.  
  21.     *.h
  22.     :tmp:*.h
  23.     "my disk:my folder:my *"
  24.  
  25. Bad wildcard patterns:
  26.  
  27.     *:tmp.h
  28.     "my disk:*:my file"
  29.  
  30. Wildcard Summary
  31. ----------------
  32.  
  33. *    - Match zero or more characters.  For example, b* matches the files "b", "bat", "belfry", and so on.
  34.  
  35. ?    - Match exactly one character.  For example b? matches "bb", "bz, and so on.
  36.  
  37. [abc]    - Match any character listed in the brackets.  For example b[cd] matches "bc" or "bd".
  38.  
  39. [a-d]    - Match any character in the range "a" to "d".  For example, b[w-z] matches "bw", "bx", "by" or "bz".
  40.  
  41. [^abc]    - Match any character not listed in the brackets.  For example b[!a-z] matches "b0" and "b2", but not "ba" or "bi".
  42.  
  43. \*    - Match a literal "*".
  44.  
  45. \?    - Match a literal "?".
  46.  
  47. \[    - Match a literal "[".
  48.  
  49. Sample Patterns
  50. ---------------
  51.  
  52. *.txt         Match all files which end with ".txt".
  53.  
  54. b*            Match all files which start with "b".
  55.  
  56. *tt*          Match all files which contain a "tt" anywhere.
  57.  
  58. [abc]*        Match all files which start with an "a" or "b" or "c".
  59.  
  60. [a-zA-Z0-9]*  Match all files which start with an alphanumeric character.
  61.  
  62. b*[0-9]       Match all files which start with a "b" and end with a number.
  63.  
  64. Wildcards and Quotes
  65. --------------------
  66.  
  67. Macintosh filenames often contain spaces.  To allow matching on such names, the nShell allows quoting of wildcard specifications:
  68.  
  69. "my *"     Match all files which start with "my" and a space.
  70.  
  71. Note that the entire string is treated as a pattern. The command:
  72.  
  73. % echo "These are my files: my *"
  74.  
  75. would attempt to match files which start with "These are my...".  To list my files, I would use the command:
  76.  
  77. % echo "These are my files:" "my *"
  78.  
  79. In this case, only the second parameter is expanded as a wildcard.
  80.  
  81. Single quotes suppress wildcard expansion, as shown below.
  82.  
  83. Suppressing Wildcard Expansion
  84. ------------------------------
  85.  
  86. Strings contained within single quotes are not expanded:
  87.  
  88.     % echo 'my favorite pattern is *.txt'
  89.     my favorite pattern is *.txt
  90.  
  91. Backslash characters may be used to force single characters to be treated literally.