Shell Secript:
Differences in execution modes:
The./sh execution is performed in the creation of a subroutine that only inherits the environment variables,
If the export declares that the subroutine's subroutine will inherit, it will not be promoted to an environment variable
Source is executed by placing the script in the context of the parent program,
Where the variable is promoted to an environment variable if export declares
Test judgment, [] judgment is the same, it is recommended to use [] the way of judging
Default variables ($, $ ...)
$0, $1.... Positional variables, representing parameter $#: the number of parameters [email protected]: represents the parameter " $" "$ $" "" $4 " $*: stands for "$1c$2c$3c$4", where C is a delimiter, default is blank
Shift: Variable offset
Each time it is executed, the position of the judge moves to the right one
Condition Judgment:
If [Conditional judgment type];then
Content
Fi
&& representative and; | | Represents or
-A: represents and; -O stands for or
If [Conditional judgment type];then
Content
elif [Conditional Judging type];then
Content
Fi
Use case .... ESAC to judge
Case $ variable in
"First variable content")
Program Segment
;;
"Second variable content")
Program Segment
;;
"*")
Exit 1
;;
Esac
Cycle:
While doing done
while [condition]
Do
Program Segment
Done
When the condition is established, the loop is executed, and the failure is stopped.
until [condition]
Do
Program Segment
Done
When the condition is set up, the standing is stopped and not established, then the circulation
For ... done
For Var in con1 Con2 Con3
Do
Program Segment
Done
Numerical processing
for (initial value; limit value; execution Step)
Do
Program Segment
Done
Random numbers and array arrays
Range of values for ${random} [0,32767]
#!/bin/bash
#
E[1]= "AAA"
E[2]= "BBB"
e[3]= "CCC"
En=3
check=$ ((${random} * ${en}/32767 + 1))
echo ${e[${check}]}
function functions:
function fname () {
Program Segment
}
Functions also have positional variables, $0,$1,$2
Debug of Shell Script
Sh:
-N: Do not execute script, only query syntax issues
-V: Output script contents to screen before execution
-X: Displays the script content you are using to the screen
Linux Shell Script First Knowledge