Shell programming
The language is divided into:
Compiled languages: first to be translated into executable format
Interpreted language: Side interpretation side Execution
Variables: The shell is a weakly typed programming language, and the variable does not need to indicate the type and initialization, but the context determines the type
Bash Variable type:
Environment variables
Local variables
Positional variables
Special Custom variables
Local variables: scope for the entire bash process
Varname=value
Local variables: Scope current Code
Local Varname=value
Environment variable: scope is the current shell process and child process
Export Varname=value
Conditional judgment
How to achieve conditional judgment in hash?
Condition Test Type:
Integer test
Character test
File test
Expressions for Conditional tests:
[Expression]
[[Expression]]
Test expression
Integer comparison:
-EQ: Tests whether two integers are equal
-ne: Not Equal
-GT: Greater Than
-LT: Less than
-ge: greater than or equal to
-le: Less than or equal to
Logical relationships between commands:
Logic and:&&
Logical OR: | |
Logical non-:!
Condition Judgment: Control structure
if judgment condition; Then
Statements
Elif judgment condition; Then
Statements
Else
Statements
Fi
How to perform arithmetic operations in the shell:
A=3
B=6
Let arithmetic op-expression
Let c= $a + $b
$[arithmetic Operation expression "
c=$[$a + $b]
$ ((arithmetic operation expression))
c==$ (($a + $b))
Expr arithmetic expression, with spaces between operands and operators in an expression, and using command references
C= ' expr $a + $b '
This article is from the "Forget the Past" blog, please be sure to keep this source http://xujingbo.blog.51cto.com/4633099/1826526
Shell Programming Details (i)