1. Use multiple commands
To run multiple commands together, you only need to input them to the same line, separated by semicolons.
Ex: data; WHO
2. Create a script file
(1) #! /Bin/bash is the first line
(2) # Add comments.
(3) Each line ends with a carriage return.
(4) grant the execution right to the script file by chmod + x
(5) call with Path
3. Display messages
You can add an echo statement to any location where extra information needs to be displayed in the shell script.
4. Use Variables
(1) Environment Variables
(2) User Variables
Variable names are case sensitive. spaces are not allowed between variables, equal signs, and variable values. As long as it is the value corresponding to the referenced variable, it must be prefixed with the $ symbol
(3) backticks: "'"
Used to assign the output of shell commands to variables.
5. Redirect input and output:
Output: ">", additional: ">"
Input (from the file): "<"
Built-in input (from the command line): "<"
6. Pipelines
Redirects the output to another command, instead of redirecting the output to a file. Use "|"
7. Mathematical computing
(1) expr: can be used to execute mathematical equations (but not good)
(2) In bash, specify a mathematical value for a variable. You can enclose the mathematical equations with dollar signs and square brackets ($ [operation. (Simpler)
However, bash shell supports integers.Algorithm. Z shell supports floating point operations
(3) floating point calculation solution
The most common method is to use the bash built-in bash calculator (BC) in the script through pipelines)
8. Exit the script.
(1) Check the exit status
$? Used to save the exit status of the last command execution. The default execution success is 0, and the unknown error is 1.
(2) Exit the command
The exit command allows you to specify an exit state when the script ends (a number or variable is available, but the range must be 0-255 ).