Common special symbols in shell are listed as follows: #;,/\ 'string' |! $ {}$? $ * "String "***?: ^ $ # $ @ 'COMMAND '{} [] [[] () | & {XX, YY, ZZ ,...}~
~ + ~ -& \ <... \> +-% =! = Output/input redirection >>><<:>&> 2 <>>>& 2 # comments) this is almost a full-market symbol, except for the "first line" that has been previously mentioned "#! The/bin/bash well number usually appears at the beginning of a line or after the complete command. This type of situation indicates that the annotation text is followed by the symbol and will not be executed. # This line is comments. Echo "A = $ A" # A = 0 due to this feature, when you do not want to execute a certain line of command temporarily, you only need to add # At the beginning of the line. This is often used in the writing process. # Echo "A = $ A" # A = 0 if it is used in the instruction, or enclosed in double quotation marks, or after the backslash, it becomes a general symbol, it does not have the above special features. ~ The Home Directory of the account is a common symbol, representing the Home Directory of the User: Cd ~; You can also add the account name "CD ~" directly after the symbol ~ User or a part of the path :~ /Bin ;~ + The current working directory. This symbol represents the current working directory. It serves the same purpose as the built-in command PWD. # Echo ~ +/Var/log ~ -Last working directory. This symbol represents the last working directory. # Echo ~ -/Etc/httpd/logs; in shell, the semicolon (command separator) is used as the "continuous command" function ". For example, Cd ~ /Backup; mkdir startup; CP ~ /. * Startup/.; the consecutive semicolon (Terminator) is dedicated to the case option and serves as the terminator role. Case "$ fop" inhelp) echo "Usage: Command-help-version FILENAME"; version) echo "version 0.1"; esac. in shell, the user should be clear that a dot represents the current directory, and two dots represent the upper directory. Cdpath = .:~ :/Home:/home/Web:/var:/usr/local in the upstream cdpath setting, the dot after the equal sign represents the meaning of the current directory. If the file name starts with "dot", the file is a special file, which is displayed only when the-A option is added to the LS command. In addition, in the regular expression, a dot represents matching a character. The content enclosed by single quotes in 'string' is considered a single string. The $ symbol representing the variable in quotation marks does not work. That is to say, it is treated as a general symbol to prevent replacement of any variable. Heyyou = homeecho '$ heyyou' # The content enclosed by double quotes is considered a single string. It prevents wildcard extension, but allows variable extension. This is different from how a single reference is processed. Heyyou = homeecho "$ heyyou" # We get home 'command' inverted quotation marks (backticks) in front of the single double quotation marks, which enclose strings. However, if the string is a command column, what will happen? The answer is no execution. To handle this situation, we must use single quotes. Fdv = 'date + % F' echo "today $ fdv" the date + % F in the inverted quotation mark is considered as an instruction, and the execution result is included in the fdv variable ., The comma symbol is often used in operations as a "segmentation" purpose. Example #! /Bin/bashlet "T1 = (A = 5 + 3, B = 7-1, C = 15/3)" Echo "T1 = $ T1, A = $, B = $ B "/forward slash (forward slash) indicates a directory in the path. CD/etc/rc. DCD.../. CD/usually a single/Represents the root directory. In the four arithmetic operations, it represents the division symbol. Let "num1 = (A = 10/2, B = 25/5)" \ backslash () The Escape Character in interactive mode, which has several functions; placed before the command, the function of canceling aliases. If it is placed before a special symbol, the function of the special symbol disappears. If it is placed at the end of the command, it indicates that the command is connected to the next line. # Type rmrm is aliased to 'rm-I '# \ RM. /*. in the log example, I add the escape character before the RM command to temporarily cancel the alias function and restore the RM command. # Bkdir =/home # echo "backup Dir, \ $ bkdir = $ bkdir" backup Dir, $ bkdir =/\ $ bkdir, escape cancels the $ variable function. Therefore, $ bkdir is output, while the second $ bkdir outputs the variable content/home. | Pipeline is a basic and important concept of UNIX systems. Connect the standard output of the previous command as the standard input of the next command. Who | WC-L makes good use of this concept, which is quite helpful for streamlining scripts .! The exclamation point (negate or reverse) usually represents the anti-logic function. For example, it is used in condition detection! = To indicate "not equal to" If ["$? "! = 0] thenecho "executes error" Exit 1fi in the Rule expression, she assumes the "anti-logic" role ls [! 0-9] in the preceding example, other files except A0, A1... A9 are displayed.: Colon in bash, This is a built-in command: "do nothing", but return the status value 0.: Echo $? # The response is 0:> F. $. The above line is equivalent to CAT/dev/null> F. $. Not only is the statement short, but the execution efficiency is much higher. Sometimes, the following usage occurs: $ {hostname ?} $ {User ?} $ {Mail ?} This line is used to check whether these environment variables have been set. If they are not set, an error message is displayed as a standard error. Similar to test or if, this type of check can basically be processed, but it is not as concise and efficient as in the previous example. In addition to the above, you must use the colon Path = $ path: $ home/fbin: $ home/fperl:/usr/local/Mozilla in the user's home directory. in bash_profile or any file with similar functions, we use colons to set the path for segmentation .? Question mark (wild card) plays a role on filename expansion that matches any character but does not contain null characters. # Ls? A1 makes good use of her features to perform exact file name matching. * Asterisks (wild card) are commonly used symbols. In filename expansion, it represents any character and contains null characters. # Ls a * A A1 access_log indicates "multiplication" during operation ". Let "fmult = 2*3" in addition to the built-in command let, there is also an operation instruction expr, the asterisk here also serves as "multiplication" role. However, be careful when using the escape character. ** Two asterisks in the power operation mean the "power" of the table in the computing age. Let "Sus = 2 ** 3" Echo "Sus = $ sus" # sus = 8 $ dollar sign variable replacement (variable substitution) representative symbol. VRS = 123 echo "VRS = $ VRS" # VRS = 123. In addition, it is defined as "end-of-line" in regular expressions ). This is often used in grep, sed, awk, and VIM (VI. The Regular Expression of $ {} variable bash defines many usage for $. The following table columns are from the online description $ {parameter:-word }$ {parameter := word }$ {parameter :? Word }$ {parameter: + word }$ {parameter: Offset }$ {parameter: offset: length }$ {! Prefix * }$ {# parameter }$ {parameter # Word }$ {parameter % word}
$ {Parameter/pattern/string }$ {parameter // pattern/string} $ * reference the execution reference variable of the script. The algorithm of the referenced parameter is the same as that of the General Command, and the command itself is 0, and then 1. Variables referenced are represented as follows: $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $ {10}, ${11 }..... for single-digit users, you can directly use a number. If the number is greater than two digits, you must use the {} symbol to enclose it. $ * Indicates all symbols that reference variables. Double quotation marks must be added as needed. Echo "$ *" also has a symbol with the same effect as $ *, but its utility and processing method are slightly different. $ @$ @ Has the same effect as $ *, but there is a difference between them. Symbol $ * considers all referenced variables as a whole. But the symbol $ @ still retains the concept of block for each referenced variable. $ # This is also a symbol related to the referenced variable. Her role is to tell you the total number of referenced variables. Echo "$ #" $? Status variable generally, Unix (Linux) processes end with the execution system calling exit. The return value is the status value. It is returned to the parent process to check the execution status of the child process. If the command program is successfully executed, the return value is 0; If the command program fails, the return value is 1. Tar cvfz dfbackup.tar.gz/home/user>/dev/nullecho "$? "$ Because the process ID is unique, it is impossible to have a repetitive PID at the same time. Sometimes, scripts need to generate temporary files to store necessary information. This script may also be used by users at the same time. In this case, the fixed file name is obviously unreliable in writing. Only dynamic file names can be generated. Symbol $ may meet this requirement. It represents the PID of the current shell. Echo "$ hostname, $ user, $ mail"> ftmp. $ use it as a part of the file name to avoid overwriting of the same file name at the same time. PS: basically, the system recycles the executed PID and then allocates it as needed. Therefore, even if the temporary file is written using the dynamic file name, other problems may occur if the script is not cleared after execution. () Command Group enclose a string of continuous commands in parentheses. This is called a command group for shell. Example: (Cd ~; Vcgh = 'pwd'; echo $ vcgh), the Command Group has a feature, shell will generate subshell to execute this set of commands. Therefore, the variables defined in the variable only act on the Command Group itself. Let's look at an example # Cat ftmp-01 #! /Bin/Basha = HCG (A = incg; echo-e "\ N $ A \ n") echo $ #. /ftmp-01incgfsh In addition to the preceding Command Group, brackets are also used in the definition of array variables; also applied in other occasions that may require the escape character to be used, such as the formula. () The role of these symbols is similar to that of the let Command. It is used in arithmetic operations and is a built-in function of bash. Therefore, the execution efficiency is much better than using the let Command. #! /Bin/bash (A = 10) echo-e "in1_value, A = $ A \ n" (A ++) echo "after a ++, A = $ A "{} braces (Block of code) sometimes appear in the script. the braces hold one or more segments of instructions or variable settings ending with a semicolon. # Cat ftmp-02 #! /Bin/Basha = hCG {A = inbc; echo-e "\ N $ A \ n"} echo $ #. /ftmp-02inbcinbc this usage is very similar to the Command Group described above, but there is a difference that it is executed in the current shell, does not produce subshell. Braces are also applied to the function. Broadly speaking, simply using braces only serves as a function without a specified name. Therefore, writing scripts in this way is quite good. This method can simplify the complexity of the script, especially for the output input. In addition, braces have another usage, as shown in {XX, YY, ZZ ,...} this combination of braces is often used in string combinations. Let's look at the mkdir {usera, userb, userc}-{home, bin, data} example. We get usera-home, usera-bin, usera-data, userb-home, userb-bin, userb-data, userc-home, userc-bin, and userc-data. This set of symbols is widely applied. If you can make good use of it, the return is simplified and efficient. In the following example, chown root/usr/{UCB/{ex, edit}, lib/{ex ?.? *, How_ex} if this usage is not supported, we have to write several rows and repeat them several times! [] Brackets are often used in Process Control and play the role of the square brackets. If ["$? "! = 0] The thenecho "executes error" Exit 1fi symbol serves as a role Rm-R 200 [1234] similar to "range" or "set" in a regular expression. In the preceding example, indicates deleting directories such as 2001,200 2 and 2003,200 4. [[] This group of symbols works basically the same as the previous [] symbols, but she allows them to directly use | and & logical symbols. #! /Bin/bashread Akif [[$ Ak> 5 | $ AK <9] thenecho $ akfi | logical symbol, which is often seen as the or logical symbol. & Logical symbols, which are often seen as the and logical symbols. & A single & symbol is used in the background and placed at the end of the complete command column, that is, the command column is put into the background for work. Tar cvfz data.tar.gz DATA>/dev/null & \ <... \> the single-word boundary symbol is defined as "boundary" in the Rule expression. For example, when we want to find the word, if we use grep the filea, you will find that words like there will also be considered as matching words. Because the coincidence is a part of there. If we want to avoid this situation, we need to add the "boundary" symbol grep '\ 'filea + plus sign (plus) in the formula, which is used to represent "addition ". Expr 1 + 2 + 3 In addition, in the Rule expression, it is used to indicate the meaning of the first character of "many. # Grep '10 \ + 9' fileb000010094259425931010009 # This symbol must be prefixed with the escape character. -Dash indicates "subtraction" in the formula ". Expr 10-2 is also the option symbol of the system command. Ls-expr 10-2 in the GNU command, if the-symbol is used separately without the name of the file to be added, it indicates the meaning of "standard input. This is a common option for GNU commands. For example, in the following example, tar xpvf-here-represents reading data from standard input. However, in the CD command, the CD command is special-this means to change the working directory to the "last" working directory. % Division (Modulo) is used to represent "division" in the formula ". Expr 10% 2 is also applied to the following $ {parameter % word }$ {parameter % word} in the Rule expression about variables. One % indicates the shortest word match, the two indicate the longest word match. = Equal sign (equals) is a symbol that is often seen when a variable is set. Vara = 123 echo "Vara = $ Vara" or path settings, or even applications for such purposes as computation or regression. = Equal sign (equals) is often seen in the condition criterion, representing "equal. If [$ Vara = $ varb! = Not equal to is often seen in the condition criterion, indicating "not equal. If [$ Vara! = $ Varb]... the symbol is slightly ^ In the rule expression, representing the "beginning" of the line.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.