Shell 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: Explanatory language
Weak type
Edge Interpretation Side Execution
Asp/asp.net/php/shell/python/perl
Shell: Weakly typed programming language
Strongly typed: The variable must be declared beforehand before it is used, and even need to be initialized:
Weak types: Variable time declarations, or even non-differentiated types:
Process oriented: Shell C
Object-oriented: JAVA Python, Perl, C + +
Variables: Memory space, naming
Memory: Addressable storage unit
Process:
Variable type: Determine the storage format and length of the data in advance
Character
Numerical
Plastic
Floating point Type
Programming Ability:
Script programming
Variable assignment: Var_name=value
Bash Variable type:
Environment variables
Local variables (local variables)
Positional variables
Special variables
Local variables:
Var_name=value: Scope for the entire script 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
Export
Two different ways:
1. Export Varname=value
2. Varname=value
Export VARNAME
Positional variables
$, $, ...
Special variables:
$? The execution status return value of the previous command:
Program execution Results
Program Status return codes (0-255)
0: Correct execution
1-255: Error execution, 1,2,127 system reserved
Output redirection:
>
>>
2>
2>>
&> redirect standard output or error output to the same file
/dev/null: Software device, bit bucket data black hole
Order execution, there may be two types of return values:
When the script executes, a child shell process is started:
Script that is started on the command line inherits the current shell environment variable
Scripts that are automatically executed by the system (not command-line startup) require a self-defined environment variable
Undo Variable:
Unset VARNAME (never add $)
View variables in the current shell
Set (including environment variables and local variables)
To view environment variables in the current shell:
Printenv
Env
Export
Script: Command stack, according to the actual needs, combined with the command flow control mechanism realization of the source program
Shebang: Magic number
#!/bin/bash
Exercise: Write a script to complete the following tasks
1. Add 5 users, User1,user2,... user5
2. Each user's password is the same as the user name, and requires that the execution result information of the passwd command not be displayed after the Add password is completed
3. After each user is added, it is shown that the user XX has been successfully added
Exercise: Write a script to complete the following tasks
1. Use a variable to save a user name:
2. Delete the user from this variable and delete its home directory
3. Display the "User Delete complete" class information
This article is from the "Richier" blog, make sure to keep this source http://richier.blog.51cto.com/1447532/1631396
Bash Script programming (1/4) variables, variable types, and other notes