When learning special characters, you may encounter shell special character problems. You can develop the Fedora Core Linux for Linux in the community-supported way, the development team of Red Hat Linux will continue to participate in the development of this release. Here we will introduce how to solve the shell special character problem, and share it with you here.
Shell special characters
In addition to common characters, shell special characters can also contain special characters with special meanings and functions. When using them, pay attention to their special meanings and scopes. The following describes these special characters.
Wildcard
Wildcard characters are used for pattern matching, such as file name matching, path name search, and string search. Common wildcard characters include *,? And the Character Sequence enclosed in square brackets. You can include These wildcards in the file name of the command parameter to form a so-called "pattern string" and perform pattern matching during execution. Represents the length of any string.) For example, "f *" matches any string that starts with "f. Note that the dot.) before the file name must be explicitly matched with the slash/) in the path name. For example, "*" cannot match. file, but ". *" can match. file.
Represents any single character.
[] Indicates a specific shell special character range. As long as the character at the [] position in the file name is within the range specified by [], the file name matches the pattern string. The character range in square brackets can be composed of directly given characters, or it can be composed of starting characters, ending characters, and intermediate hyphen-) that indicate a limited range. For example, f [a-d] and f [abcd] serve the same purpose. Shell uses all file names that match the pattern string specified in the command line as command parameters to form the final command and then execute the command.
Table 10-1 describes the meanings of these wildcards. Table 10-1 wildcard meaning example mode string meaning
The names of all files in the current directory.
* Text *
The names of all files with Text in the current directory.
[AB-dm] *
Names of all files starting with a, B, c, d, and m in the current directory.
[AB-dm]?
The names of all files starting with a, B, c, d, and m in the current directory with only one special shell character.
/Usr/bin /??
The names of all files with two characters under the/usr/bin directory.
Note that the hyphen "-" is only valid in square brackets and indicates the character range. For example, it becomes a common character outside square brackets. And * and? Wildcards are used only outside square brackets. If they appear in square brackets, they also lose the wildcard capability and become common characters. For example, the mode "-a [*?] Only one pair of square brackets in abc is a wildcard, * and? Are common characters. Therefore, the matching strings can only be-a * abc and-? Abc.
Finally, we will explain some issues that need to be paid attention to when using wildcards. Because *,? And [] are of special significance for shell, so these characters should not appear in normal file names. In particular, do not show them in the directory names; otherwise, the shell special characters may be infinitely recursive. Note that if the directory does not have a file name that matches the specified mode string, the shell special character uses this mode string as a parameter to pass to the relevant command. This may be the reason for the special characters in the command.
- Basic Shell programming syntax in Linux
- Process Control for Shell programming in Linux
- How to program and run a Shell program in Linux
- Linux Shell programming bash Internal commands
- Introduction to uncommon shell Combination control keys