Shell Programming Script Programming
Compilers, interpreters
Programming languages: Machine language, assembly language, advanced languages
Static language: Compiled language
Strongly typed (variable)
Convert into executable format in advance
C, C + +, JAVA, C #
Dynamic language: Interpreted language, on the fly
Weak type
Edge Interpretation Side Execution
PHP, SHELL, Python, Perl
Process oriented: Shell, C
Object-oriented: JAVA, Python,perl, C + +
Variables: Memory space, naming
Memory: Addressable storage unit
Process:
1 + 100:
Variable type: Determine the storage format and length of the data in advance
Character
Numerical
Integral type
Float type: 11.23 1.123*10^1, 0.1123*10^2
Shell: Weakly typed programming language
Strong: Variables must be declared beforehand and even initialized before they are used;
Weak: variable time declaration, even the type is not differentiated;
Variable assignment: Var_name = value
Bash Variable type:
Environment variables
Local variables (local variables)
Positional variables
Special variables
Local variables:
Set VARNAME = VALUE: scope for the entire bash process
Local variables
Local Varname=value: Scope is the current code snippet
Environment variable: scope is the current shell process and its child processes
Export Varname=value
Varname=value
Export VARNAME
Export
Positional variables:
$,...
Special variables
$? : The execution status return value of the previous command
Program execution. There may be two types of return values:
Program execution Results
Program Status return codes (0-255)
0: Correct execution
1-255: Error execution, 1, 2, 127 system reserved;
The script starts a child shell process when it executes
Scripts that are started on the command line inherit the environment variables of the current shell
Scripts that are automatically executed by the system (not the command line) need to self-define the required environment variables
Reference variable
${varname}: Parentheses can be omitted
Output redirection:
>
>>
2>
&>
/dev/null: Software device bit bucket data black hole
Linux-shell Programming (I.)