Two. Special characters in the shell
In addition to using ordinary characters in the shell, special characters with special meaning and functionality can be used. At the time of use, you should pay attention to its special meaning and scope of action. These special characters are described below. 1. Wildcard wildcard is used for pattern matching, such as file name matching, road scripping search, string lookup, etc. Commonly used wildcards are * ,? and character sequences in square brackets []. The user can include these wildcards in the file name as the command parameter, constitute a so-called "mode string" and perform mode matches during the execution process. * Represents any string (length can be inequal), for example: "f *" matches any string of the head head. However, it should be noted that the dots (.) And slash (/) in the path before the file must be explicitly matched. For example, "*" cannot match .file, and ". *" Can match .file. ? Represents any individual characters. [] Represents a specified character range, as long as the [] location in the file name is within the [] location specified in [], then this file name matches this mode string. The character range in square brackets can be composed of a direct-given character, or consist of a starting character representing a defined range, a termination character, and an intermediate hyphen (-). For example, F [A- D] is the same as F [ABCD]. The shell will use all the file names that match the mode strings specified in the command line to form the final command, and then execute this command. Here we give the table 10-1 to explain the specific meaning of these wildcards. Table 10-1 Wildcard Meaning Example Mode Strings * The name of all files in the current directory. * Text * The name of the file containing text in all file names in the current directory. [AB-DM] * The name of all files starting with A, B, C, D, and M. [AB-DM]? All the names of all the files starting with A, B, C, D, M and the back of one character with a character. / usr / bin / ?? Directory / USR / bIN name of all files named two characters. It is particularly important to note that even characters "-" are only valid in square brackets, indicating the character range, as in square brackets, it is a normal character. And * and? Only in square brackets are wildcards, if they appear in square brackets, they have lost the ability of wildcards and become ordinary characters. For example, only one pair of brackets in the pattern "- a [*?] Abc" are wildcards, * and? All ordinary characters, so it matches the string that can only be - a * ABC and - a? ABC. Finally, some issues that need to be careful when using wildcards. Since * ,? and [] have a relatively special meaning for the shell, these characters should not appear in the normal file name. Especially in the directory name, do not appear, otherwise shell matches the endless manner. It is also a point to pay attention to: If there is no file name that matches the specified mode string in the directory, the shell will use this mode string itself as a parameter to pass the relevant command. This may be the reason why the current special characters in the command. 2. Quotation marks are divided into three types: single quotes, double quotes and reverse numbers. * Single quotes' characters from single quotes appear as ordinary characters. After the special characters are enclosed in single quotes, they will lose their original meaning, but only as a normal character interpretation. For example: $ String = '$ PATH' $ Echo $ String $ PATH $ visible $ Maintaining its own meaning, as a normal character appears. * Double quotation marks "The characters enclosed by double quotes, except for $,, ', and" these characters are still special characters and retain their special features, and the rest are treated as ordinary characters.