# |
Comment symbol (hashmark[comments]) 1. At the beginning of the shell file, as an include tag, #!/bin/bash; 2. Use other places as annotations, in one line, #后面的内容并不会被执行, unless; 3. However, when surrounded by single/double quotes, the #作为 the # character itself, does not have a comment function. |
; |
As a delimiter for multiple statements (Command separator [semicolon]). You can use semicolons to separate multiple statements when they are placed on the same line. Note that sometimes semicolons need to be escaped. |
;; |
Continuous semicolon (Terminator [double semicolon]). When using the case option, as a terminator for each option. In bash version 4+, you can also use the [;; &], [; &] |
. |
Point number (dot command [period]). 1. Equivalent to bash built-in command source, such as:
Code
123 |
#!/bin/bash . data- file #包含data-file; |
2. As a part of the file name, at the beginning of the file name, indicating that it is a hidden file, LS is generally not displayed (Ls-a can be displayed); 3. As the directory name, one point represents the current directory, and the two points represent the upper directory (the parent directory of the current directory). Note that more than two points do not appear unless you enclose them in quotation marks (single/double) as the dot character itself; 4. In the regular expression, the dot number represents any one character. |
" |
Double quotation marks (partial quoting [double quote]). Partial references. The contents surrounded by double quotes can allow variable expansion, and also allow the existence of escaped characters. If the double quotation marks themselves appear inside the string, they need to be escaped, so it is not necessarily true that the double quotes are paired. |
‘ |
Single quotation mark (full quoting [quote]). Single-quote-enclosed content, considered a single string, suppresses variable expansion within quotation marks, all characters nonspacing as the character itself (except for the single quotation mark itself), and single quotes must appear in pairs. |
, |
Comma (comma operator [comma]). 1. In a series of mathematical expressions connected, this string of mathematical expressions is evaluated, but only the last evaluation result is returned. Such as:
Code
1234 |
#!/bin/bash let t1=((a=5+1, b=7+2)) echo t1=$t1, a=$a, b=$b ## 这个$t1=$b; |
2. Used in the parameter substitution, indicates the first letter lowercase, if two comma, then all lowercase, note that this feature was added in bash version 4. Example:
Code
1234 |
a= "ATest" echo ${a,} echo ${a,,} ## 前面输出aTest,后面输出的是atest。 |
|
\ |
Backslash, anti-skew lever (escape [backslash]). 1. Before the special symbol, escape the function of the special symbol, only the special symbol itself, which is used in the string; 2. Placed at the very end of a line of instructions, indicating that the subsequent carriage return is invalid (in fact, it escapes the Enter), and the input of the following new line is still part of the current instruction. |
/ |
Slash, diagonal bar (Filename path separator [forward slash]). 1. As a delimiter for a path, only one diagonal bar in the path represents the root directory, and the path starting with the ramp represents the path from the root directory; 2. Represents the division symbol when it is an operator. such as:
code
TD class= "Gutter" >1
a=4 /2 |
|
' |
inverted quotation marks, followed by quotation marks (Command substitution[backquotes]). Command replacement. This quote encloses the command, which can execute the enclosing command and assign the result of the execution to the variable. Example:
code
123 |
a= ' dirname '/tmp/x.log ' ' ## The result returned by DirName is assigned to a, ## Note that here Mitchell specifically uses anti-quotes and single quotes, note the difference. |
|
: |
Colon (null command [colon]). Null command, this command does nothing, but has a return value of 0 (that is, true). The function of this command is very wonderful. 1. Can do the condition of the while dead loop; 2. As a placeholder in the If branch (that is, when a branch does nothing); 3. Place it in a delimiter that must have a two-dollar operation, such as:
code
1 |
: ${username= ' whoami |
4. In parameter substitution, assign a value to a string variable, and in the redirect operation (>), truncate the length of a file to 0 (:>> When this is used, the target exists and nothing is done, this can only be used in ordinary files, not in pipelines, symbolic links and other special files; 5. Even you can use annotations (#后的内容不会被检查, but: after the content is checked, if there is a syntax error in the statement, 6. You can also act as a domain delimiter, such as in the environment variable $path, or passwd, with the presence of a colon as a domain delimiter; 7. You can also use a colon as the function name, However, this will change the meaning of the colon (if you are not careful as the function name, you can use unset-f: to cancel the definition of function). |
! |
Exclamation point (reverse (or negate) [bang],[exclamation Mark]). To reverse a test result or exit status. 1. The anti-logic, such as the next! =, which is not equal to the expression; 2. To reverse, such as: LS a[!0-9] #表示a后面不是紧接一个数字的文件; 3. In different environments, the exclamation point can also appear in the indirect variable reference; 4. In the command line, can be used for the historical command mechanism of the call, you can try!$,!#, or!-3 look, but note that this feature cannot be used in the script file (disabled). |
* |
asterisk (Wildcard/arithmetic Operator[asterisk]). 1. As a wildcard character that matches the filename extension, it can automatically match every file in a given directory; 2. The regular expression can be used as a character qualifier, indicating that its preceding matching rule matches any time; 3. Multiplication is represented in arithmetic operations. |
** |
Double star number (asterisk). The arithmetic operation represents the exponentiation operation. |
? |
Question mark (Test operator/wildcard[question Mark]). 1. Indicate condition testing; 2. The C-style ternary operator ((Condition?true-result:false-result)) is represented in double brackets; 3. Parameter substitution expressions are used to test whether a variable has a value set; 4. As a wildcard character, used to match the filename extension attribute, used to match a single character; 5. In a regular expression, it means to match its preceding rule 0 or 1 times. |
$ |
Dollar symbol (Variable substitution[dollar sign]). A meaning has been expressed before. 1. As a leader of a variable, use it as a variable substitution, which refers to the contents of a variable, such as: echo $PATH ; 2. In the regular expression is defined as the end of line (end of lines). |
${} |
Parameter substitution (Variable substitution). Please refer to the specific content for more information. |
$ ' ... ' |
The reference content is expanded to execute the escaped content within single quotation marks (the single quotation marks are originally referenced), which expands the octal and hexadecimal values of one or more [\] escapes within the quotation marks to ASCII or Unicode characters. |
$*, [email protected] |
Positional parameters, which are used when using a script file, when passing parameters. Both can return all parameters of the calling script file, but $* returns all parameters as a whole (string), while [email protected] returns each parameter as a unit with a list of parameters. Note that you need to enclose $*,[email protected] in double quotes when you use it. These two variables take the effect of $ifs, if in practice, to consider some of the details, more please consult the reference location parameters (positional Parameters) related information. |
$? |
When used, the value of this variable returns the exit status code value of the last command, function, or script, or 0 if there is no error, or 0 if not, indicating that there was an error in the last execution. |
$$ |
The process ID variable that holds the process ID value that runs the current script. |
() |
parentheses (parentheses). 1, command group. Commands that are enclosed by a set of parentheses are command groups that are executed in the command group in the shell (Subshell). Because it is run inside a child shell, there is no way outside the parentheses to get the value of the variable inside the parentheses, but in turn, the command group is able to get outside values, which is somewhat like the relationship between local variables and global variables, in the implementation, if you encounter the CD to sub-directory operation, And when the operation is completed to return to the current directory, you can consider using Subshell to handle; 2. Used for initialization of arrays. |
{Xx,yy,zz,...} |
Curly brace Extension (brace Expansion). This extension can be used in the command to extend the argument list, and the command will be extended according to the pattern separated by the parentheses in the list. Note that there is no space in the curly brace extension, and if it does, it must be escaped or quoted. Example:
Code
1 |
echo {a,b,c}-{\ d, " e" , ‘ f‘ } |
|
{A.. Z |
The extension of this curly brace extension is added to bash version 3 o'clock, and you can use {A. Z} represents a A-Z list of all characters, this way the extension Mitchell tested, as if only for a-z,a-z, and the number {Minno. Maxno} is extended in this way. |
{} |
code block (curly brackets). This is an anonymous function, but unlike a function, a variable inside a block of code can still be accessed behind a block of code. Note: The inside of the curly braces requires a space and a statement to separate them. In addition, in the xargs -i words, it can also be used as a placeholder for text to mark the position of the output text. |
{} \; |
This {} is the name of the path, which is not built in the shell and is now exposed to a situation that seems to be used only in the Find command. Note the following semicolon, which is the find command sequence that ends the options in the command -exec , and, when actually used, to escape to avoid being understood by the shell. |
[] |
The brackets (brackets). 1. The test indicates that the shell will test the expression within [], noting that [] is part of the shell's built-in test and not a link to the use of external commands /usr/bin/test ; 2. In the context of an array, an array element is represented, and the position of the array element is filled in square brackets to obtain the content of the corresponding position, such as:
Code
12 |
Array[1]=xxx echo ${Array[1]}; |
3. Represents a range of character sets, in a positive expression, the square brackets indicate the range of character sets that the location can match. |
[[]] |
Double brackets (double brackets). This structure is also the test, test [[]] in the expression (the Shell keyword). This is more than a single-bracket to prevent logic errors in the script, such as: &&,| |,<,> operator can be in a [[]] inside the test pass, but in [] but can not pass. [[]] there is no filename extension (filename expansion) or Word delimiter (word splitting), but it can be extended with parameters (Parameter expansion) and command substitution (commands substitution). Do not use file name wildcards and separators like whitespace. Note that the shell automatically performs a conversion comparison if octal, 16, etc. are present in this case. |
$[...] |
The word expression represents an integer extension (integer expansion) that executes an integer expression inside the square brackets. Cases:
Code
12345 |
a=3 b=7 echo $[$a+$b] echo $[$a*$b] ##返回是10和21 |
|
(()) |
Double brackets (doubles parentheses). Represents an integer extension (expansion). The function is similar to the above $[], but it is important to note that $[] returns the value of the expression inside, and (()) just executes and does not return a value. If the value of the variable changes after the execution of both, it will affect the running of the successor code. Variables can be assigned to the variable to operate a single-eye operator, can also be two mesh, trinocular operator. |
>,&<,>&,>>,<,<> |
Redirect (redirection).
Code
1 |
scriptname >filename |
Redirect the output of the scriptname to the file filename and overwrite if the file exists;
, the command's standard output (STDOUT) and standard error (STDERR) are redirected to the file filename;
REDIRECT the command's standard output (STDOUT) to the standard error (STDERR);
Code
1 |
scriptname >>filename |
, the ScriptName output (same as >) is appended to the file Filenmae and created if the file does not exist.
Open filename This file is used to read or write, and to give the file specified I for its file descriptor (file descriptor), the files will be created if they do not exist. |
(command) >,< (command) |
This is process Substitution. When using the note, there is no space between the brackets and <,>, or error. It works a bit like a channel, but unlike a pipe in usage, the pipeline runs as a sub-process, and this command /dev/fd/ produces a similar /dev/fd/63 , temporary file that is /dev/fd/62 used to pass data. Mitchell personal speculation that this method to pass, because the front and back two is not part of the same process, so need to share files to pass the data (so that the pipeline should have the same file?). Online Some people say this is only a shared file, but after testing, found that although there is /dev/fd/63 such a file, but this file is actually pointing to pipe:[43434] such a link to the channel. |
<< |
Double less than sign (here-document[double and then marks]). This is also known as here-document, which is used to redirect subsequent content to the stdin of the left command. << can save formatting time, and make it easier to handle command execution. In the implementation of the only need to enter the << and terminator marker, and then (usually after the carriage return) you can enter anything, as long as the last new line entered the Terminator, you can complete the import of data. When using here-document, you can keep spaces, line breaks, and so on. If you want to make the shell script a little neater, you can put a hyphen (-) between the << and Terminator characters. |
<<< |
Three less than sign (here-strings). Here-strings are similar to Here-document, here-strings syntax: command [args] <<<["]$word["] ; the $word expands and serves as a command stdin. |
<,> |
Less than, greater than sign (ASCII Comparison). ASCII comparison, is the ASCII comparison of the variables, strings? Numbers? Uh ... This one... Isn't that ASCII comparison? |
\<...\> |
The Word interface character (word boundary). This is a special delimiter used in regular expressions to mark the boundaries of words. For example: The will match There,another,them and so on, if only to match the, you can use the Word interface character,\<the\> can only match the. |
| |
Piping (pipe). Piping is the concept of Linux,unix, is very basic, is also a very important concept. Its function is to put the output (stdout) of the command produced before the pipeline (left) as input (stdin) of the command after the pipe (right). For example ls | wc l , a pipeline can be used to connect commands together. Note: The pipeline is the standard output for each process as the standard input for the next command, and the standard output during the period cannot span the pipeline as a standard input for subsequent commands, such as:Cat FileName | Ls-al | sort# #想想这个的输出? At the same time, pipelines run as sub-processes, so pipelines do not cause variables to change. |
>| |
Forced redirection (force redirection). This forces the overwriting of files that already exist. |
& |
With the number (Run job in Background[ampersand]). If the command is followed by A & symbol, this command will run in the background. Sometimes, a command that runs in the background in a script may cause the script to hang and wait for input, which can be fixed by using the wait command after the original script. |
&&,| | |
Logical operator (logical operator). In the test structure, you can use these two operators to connect two logical values. is when the test condition has a true time to return 0 (true), the false;&& is when the test conditions both are true when the return is True (0), there is false for false. |
- |
Minus sign, hyphen (Hyphen/minus/dash). 1. As an option, prefix [option, prefix] is used. The option flag used for the command or filter, and the prefix for the operator. Such as:
Code
123456789 |
## COMMAND -[选项列表] ls -al sort -dfu $ file set -- $variable if [ $ file -ot $file2 ] then echo "$file is older than $file2." fi |
2. Source or purpose of redirection for stdin or stdout [dash]. We can do this when there are no bunzip2 patches in tar:
Code
123 |
bunzip2 linux-2.6.13. tar .bz2 | tar xvf - ##将前面解压的数据作为tar的标准输入 ##(这里使用一个-表示) |
Note: At the time of implementation, if the file name starts with [-], then it may be an error to add this as a directional operator, and the appropriate prefix path should be added to the file to prevent this from happening, as in the case of the echo variable, if the variable starts with [-]. You may also have unexpected results, and you can use double quotes to refer to scalars for insurance purposes:
Code
123 |
var= "-n" echo $var ## 试试看有什么输出? |
Also, this representation is not built in bash, to achieve this effect, you need to see whether the software you use to support this operation; 3. Indicates the previous working directory (previous working directory), so if you want to put the CD back to the previous path in the other directory, you can use CD-to achieve the purpose, in fact, here [-] using the environment variable $OLDPWD, note: here the [ -] and the previous point is different; 4. Minus or minus sign, used in arithmetic operation. |
= |
equal sign (equals). 1. Assignment operation, assigning values to variables, there are spaces on both sides of the equal sign; 2. Appearing as a comparator in the comparison test, it is important to note that if you appear as a comparison in brackets, you need to have a space character on both sides of the equals sign. |
+ |
Plus (plus). 1. Arithmetic operator, which represents addition; 2. In a regular expression, the matching rule that represents the preceding match is matched at least once; 3. As an option tag in a command or filter, use + in some commands or built-in commands to enable certain options, use-to suppress; 4. In parameter substitution (parameter substitution), the + prefix represents the substitution value (when the variable is empty, use the value after +) |
% |
Percent (Modulo[percent sign]). 1. In arithmetic operations, this is the modulo operator, that is, the remainder of the two numbers after the division operation; 2. In parameter substitution (parameter substitution), it can be used as a pattern match. Example:
Code
1234567 |
p=b*9 var= "abcd12345abc479" echo ${var%p}, ${var%%p} ##从右边开始查找(想想从左是那个符号?) ##任何在b和9之间的内容(含) ##第一个是找到最短的符合匹配项 ##后一个是找最大符合的匹配项(贪婪匹配?) |
|
~ |
Wave (Home Directory[tilde]), this is the same as the internal variable $home. The default represents the current user's home directory (home directory), which is consistent with the ~/effect, if the tilde followed by the user name, the user's home directory is indicated, |
~+ |
Current working directory (working directory). This is the same as the built-in variable $pwd. |
~- |
Previous working directory (previous working directory). This is consistent with the internal variable $oldpwd, and the previous [-] is the same. |
=~ |
This is a regular expression match, as described in Bash version 3. can be used in [[]] tests, such as:Var= "This is a test message." [["$var" =~ Tf*message]] && echo "Sir. Found that. "| | echo "Sorry Sir. No match be found. " # #你可以修改中间的正则表达式匹配项, regular expressions can but do not necessarily need to be enclosed in double quotes. |
^ |
The caret character (caret). 1. In the regular expression, as a line of the beginning (beginning-of-line) position marker; 2. In parameter substitution (Parameter substitution), there are two types of this usage, one for the caret ( ${var^} ), or two ( ${var^^} ) for the first letter capitalized, all uppercase (Bash version >=4). |
Blank |
White space character (whitespace). Whitespace characters are not just spaces (spaces), but also tabs (tabs), blank lines (blank lines), or combinations of these. Can be used as a delimiter for a function, separate commands or variables, blank lines do not affect the behavior of the script, so you can use it to plan script code to increase readability, in the built-in special variable $ifs you can use for some commands to input parameters to split, which is the default is the white space character. If there are whitespace characters in a string or variable, you can use quotation marks to circumvent possible errors. |