This article mainly summarizes some of the basic knowledge worth noting in shell programming.
1 .#! /Bin/Bash must be placed in the first line of the file
2. num = 2. When values are assigned, spaces are not allowed on both sides.
3. Echo "this is $ {num} Nd", the role of parentheses
4. Shell default value assignment is string value assignment. Eg Var = 100 Var = $ var + 100 echo $ var result: 100 + 100
5. Integer Operation
Var = 100.
(1) Let "Var + = 1"; let indicates mathematical operations
(2) Var = $ [Var + = 1]; $ [] perform mathematical operations on the expressions in parentheses before outputting them.
(3) Var = 'expr $ var + 1'; expr is used for integer calculation. Pay attention to the spaces on both sides of the plus sign. ', not single quotation marks', indicates executing the shell command in.
6. The shell comparison operator also uses = instead of =. At this time, the = operator can have spaces or no space on both sides.
7. Shift command
You can also add a parameter to delete a parameter from the beginning.
The content of EG test. Sh is as follows:
#! /Bin/bash
Echo $1 $ #
Shift 2
Echo $1 $ #
Run./test. Sh 1 2 3 4
Result: 1 4
3 2
8. In shell, the function is called by function name without brackets.
When passing parameters to a function, you can directly follow the function name.
Eg
Show ()
{
Echo $1
}
Show VaR
9. Shell debugging
Sh-x yourscript executes the script and displays the values of all variables
Sh-N yourscript: This command returns all syntax errors.