When you log on to Linux, you can see a shell prompt that marks the start of the command line. You can enter any commands and parameters at the end of the prompt. For example, when a user logs on to $ date 2 11 23 01:34:58 CST 1999 $, the user actually enters the shell, which follows certain syntax to explain the input command and pass it to the system. The first word entered in the command line must be the name of a command, and the second word is the option or parameter of the command. Each word in the command line must be separated by spaces or tabs. The format is as follows: $ Command Option Arguments Option and parameter www.2cto.com Option include one or more letters of code, which has a minus sign (minus sign is necessary, Linux uses it to distinguish between options and parameters ), option can be used to change the type of the command execution action. For example, $ ls motd passwd $ is an optional ls command. It can list all files in the current directory, only the names of each file are listed, and no more information is displayed. $ Ls-l total 2-rw-r -- 2 wzh book 22 Apr 20 motd-rw-r -- 2 wzh book 796 Apr 20 passwd $ add-l option, A row of information, such as the data size and the last modification time, will be listed for each file. Most commands are designed to accept parameters. A parameter is one or more words entered after the option in the command line, for example: www.2cto.com $ ls-l text-rw-r -- 2 wzh book 22 Apr 20 20:37 motd-rw-r -- 2 wzh book 796 Apr 20 20:37 passwd $ text will be displayed all files in the directory and their information. Some commands, such as ls, can contain parameters, while some commands may require some minimum parameters. For example, the cp Command requires at least two parameters. If the number of parameters does not meet the command requirements, shell will provide error information. For example, $ cp-I mydata newdata note: the option in the command line is prior to the parameter input. The command line feature command line is actually a text buffer that can be edited. You can edit the input text before pressing enter. For example, you can use the BACKSPACE key to delete the character you just typed, delete it in the whole line, or insert a character so that when you enter a command, especially a complex command, if a typing error occurs, you do not need to re-enter the entire command. You can use the edit operation to correct the error. The up arrow can be used to re-display the just-executed command. This function can be used to re-execute the previously executed command without re-typing the command. Www.2cto.com bash stores the list of commands you have previously typed. This list is called the command history table. Click the arrow to display each command on the command line. Similarly, you can move the down arrow in the command list to display previous commands on the command line. You can modify and execute these commands. This feature is described in detail in section 10.4. Multiple commands can also be placed in a command line and separated by semicolons. For example, $ ls-F; cp-I mydata newdata can also enter a command in several command lines and use a backslash to continue a command line to the next line. The cp command on $ cp-I \ mydata \ newdata is input in three lines. The start two lines end with a backslash and the three lines are used as one command line. In shell, in addition to common characters, special characters with special meanings and functions can also be used. When using them, pay attention to their special meanings and scopes. The following describes these special characters. Wildcard www.2cto.com is 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 any string (length can be different). For example, "f *" matches any string that starts with "f. However, it should be noted 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 specified 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, and can also be composed of starting characters, ending characters, and intermediate hyphens (-) 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 of www.2cto.com. * 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, followed by only one 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 name; otherwise, the Shell matching may be passed in infinitely. In addition, if the directory does not contain a file name that matches the specified mode string, Shell will use this mode string as a parameter to send it to related commands. This may be the reason why a special character exists in the command. In shell, www.2cto.com quotation marks are divided into three types: single quotation marks, double quotation marks, and reverse quotation marks. Single quotation marks 'all characters enclosed by single quotation marks are common characters. When special characters are enclosed in single quotes, they will also lose their original meaning and will only be interpreted as common characters. For example, $ string = '$ path' $ echo $ string $ PATH $ visible $ retains its meaning and appears as a common character. Double quotation marks "www.2cto.com" are characters enclosed by double quotation marks. Except for the characters $, \, ', and', they are still special characters and keep their special functions. Other characters are still treated as common characters. For $, it is to replace this variable and $ with the variable value specified later. For \, it is an escape character, it tells shell not to perform special processing on the character after it, just as a common character. You can imagine that the double quotation marks must contain only four characters '$,', and. If no \ is added before the pair, Shell will match it with the previous one. For example, assume that the value of PATH is. :/usr/bin:/bin. Enter the following command: $ TestString = "$ PATH \" \ $ PATH "$ echo $ TestString. :/usr/bin:/bin \ "$ PATH $ readers can try the result without adding \ before the second double quotation mark. The keys corresponding to the character 'quotation marks (') are generally located in the upper left corner of the keyboard. Do not confuse them with single quotation marks. The string enclosed by backquotes is interpreted by shell as a command line. During execution, shell first executes the command line, and replaces the entire anti-quotation mark (including two anti-quotation marks) with its standard output result. For example, when $ pwd www.2cto.com/home/xyz $ string = "current directory is 'pwd'" $ echo $ string current directour is/home/xyz $ shell executes the echo command, first, run the command pwd in 'pwd', replace the output result/home/xyz with the 'pwd', and finally output the whole result after the replacement. This function can be used to replace commands. That is, the execution result enclosed by backquotes is assigned to the specified variable. For example, $ today = 'date' www.2cto.com $ echo Today is $ today Today is Mon Apr 15 16:20:13 CST 1999 $ anti-quotation marks can also be nested. However, you must note that the inner anti-quotation marks must be escaped using a backslash. For example: $ abc = 'echo The number of users is \ 'who | wc-l \ ''$ echo $ abc The number of users is 5 $ can also be used in The command line between backquotes. use special characters of shell. Shell is used to get the result of the command in ''. It actually needs to execute the command specified in. Special characters in the command, such as $ ,",? And ''can contain any legal Shell command, such as $ ls note readme.txt Notice Unix. dir $ TestString = "'echo $ home' 'ls [nN] * '" www.2cto.com $ echo $ TestString/HOME/yxz note Notice $ in other cases, you can try it yourself. In shell programming, comments are often used to annotate certain body lines to increase program readability. In Shell, the text line starting with the character "#" represents the comment line. Author: jiujiubuzui