Special characters of shell scripts and special characters of shell scripts
1. # comment ,#! Besides, echo $ {PATH # *:} parameter replacement does not represent annotation, numeric conversion, and echo $(2 #101011) 2 .; command Line separator. Multiple commands can be written in one line. echo hello; echo there3.; the Code for copying the terminate case option is as follows:
Case "$ variable" inabc) echo "\ $ variable = abc"; xyz) echo "\ $ variable = xyz"; esac4 .. hide the file prefix. command is equivalent to source. indicates the current directory .. indicates matching a single character in the Regular Expression of the upper-level directory
5. "", ''double quotation marks, single quotation marks. variables can be referenced in double quotation marks, but not in single quotation marks. They are used to organize special characters 6 .\
Escape Character 7./file name separator, division operation 8. '(button below Esc)
Post-reference, replace 9 with the command .:
Empty command, equivalent to "NOP", can also be considered as the shell built-in command "true" has the same effect 10 .! Inverse Operator! = Not equal to 11 .*
Universal match, mathematical multiplication in regular expressions ** Power Calculation 12 .? In the test operation regular expression ,? Match any single character 13. $ Replace the variable symbol with the line terminator $ {} in the regular expression $ *, $ @ location parameter $? Exit Status $ process ID14. () Command Group, (a = hello; echo $ a). Run the command list in () as a sub-shell. the variable in () is not available for the rest of the script because it is in the sub-shell. array initialization: array = (element1, element2, element3) 15. {xxx, yyy, zzz}
Extension cat {file1, file2, file3}> combined_file in braces. Combine file1, file2, and file3 and redirect them to commbined_file. spaces are not allowed in braces.
16. {} code block. in fact, this structure creates an anonymous function. however, unlike the function, the variables declared in it are still visible to other parts of the Code in the script. copy the Code as follows: # Content in the code block, external access, I/O redirection 1 :#! /Bin/bash 2: 3: File =/etc/fstab 4: 5: # variables in this code block, external access to 6: {7: read line1 8: read line2 9 :}< $ File 10: 11: echo "First line in $ File is" 12: echo "$ line1" 13: echo 14: echo "Second line in $ File is" 15: echo "$ line2" 16: 17: exit 0 # Save the result of a code block to a File
17 .{}\;
The path name is generally used in the find command. Note: The-exec18. [] test array element used to end the sequence of the find command, for example, array [1] = abc character range, use 19 in a regular expression. [[]
Put the expression test in [] 20. () Extension of mathematical computing 21.> & >>&> <redirect scriptname> output of the filename redirection script to the file, overwrite the original content command &> filename to redirect stdout and stderr to the file command> & 2 to redirect stdout and stderrscriptname> the filename redirection script is output to the file and added to the end of the file, if no file exists, create the file. 22. <
Redirection, <used in "here document", <used in "here string"
23. \ <, \>
The word boundary in the regular expression grep '\ <the \> 'testfile24. | pipeline, analyzes the output of the front-side command, and uses the output as the input of the back-end command
25.> | force redirect 26. | logic or 27. & run the command in the background. A command is followed by a command, which indicates that the copy code in the background is as follows:
1 :#! /Bin/bash 2: 3: for I in 1 2 3 4 5 6 7 8 9 10 4: do 5: echo-n "$ I" 6: done &
Note that the last done & 28. & logical and