1shellscript is a program written using the shell function. This program uses a plain text file to write some shell syntaxes and commands in it with regular expressions, pipeline commands, data stream redirection, and other functions to achieve the purpose of processing 2 simply put,
1. shell script is a program written using the shell function. This program uses a plain text file to write some shell syntax and commands in it with regular expressions, pipeline commands, data stream redirection, and other functions to achieve the purpose of processing
2. Simply put, shell scripts are like batch processing files in the early DOS era (. bat), the simplest function is to write a lot of commands together, so that users can easily process complex operations at once.
3. shell script is a good tool for system management, but it is not enough to process a large amount of data operations because it is slow, the cpu resources used are too many, leading to poor allocation of host resources.
4 shell script considerations
1. analyze and execute commands from top to bottom and from left to right
2. execute commands as mentioned in chapter 5. multiple blank spaces between commands and parameters will be ignored.
3 blank lines are also ignored, and the resulting keys are also considered as space keys.
4. if a row contains too many contents, you can use \ [Enter] to expand to the next row.
5 # annotations
5. we can use source xx. sh to execute the script, but this script is executed in the parent process, so the variable degree in the script can take effect.
6. use the judgment symbol []
1. each component in the brackets [] must be separated by a space key.
2. it is best to enclose the variables in brackets in double quotation marks.
3. it is recommended that all variables in brackets be enclosed in single or double quotation marks.
7. default shell srcipt variables
1. the script file name is $0, and the first parameter is $1 ......
2 $ # indicates the number of parameters
$ @ Represents $1 $2 $3 ...... meaning that each variable is independent. All parameter strings
$ * Is similar to $ @.
8 shift in the shell script moves the variable, and the variable can be followed by a number to remove the first few parameters.
9 trace and debug shell scripts
Sh [-nvx] script. sh
-N: do not execute the script. only query the syntax.
-V first outputs the script content to the screen before executing the script
-X can output the entire script execution process to the screen.