Principles of Programming:
1, Introduction to Programming:
Early programming:
Driver default hardware can not be used;
The need for communication between the different instructions of the manufacturers of hardware devices, we need drivers to "explain";
Now programming:
Based on high-level language, as well as ultra-high-level language, better enable programmers to implement programming;
Programming languages Category:
High-level language, ultra-high-level language need to "translate" into computer-readable language (binary instructions)
Interpreted language - Progressive translation, line by line shell python JAVA
bash -x filename.sh
Compiled - a compilation of all the implementation of C language C ++ C # JAVA
Program = instruction + data
Object-oriented - focusing on the data programming language
Process for - focus on instruction
Programming language implementation:
[ Line by line]
1, the order of execution
2, the loop executes - * for (traversing) * whlie (loop condition) an until (and while the opposite)
3, choose to perform - a branch if * case *
2. Introduction shell scripting language
Pros: call os (operating system) command line to achieve all the features
Cons: no library calls (to distinguish Python)
shell script include: 1, the command * * (very important) 2, variable (global variables, local variables, local variables, parameter passing) 3, logic
shell first words! ! ! (Must be written)
#! / bin / bash - defined script interpreter (# is generally considered a comment line, where special) shebang
#!/usr/bin/python
/ etc / shells - to view the current file system supported by the shell
SHELL $ echo - check the current drawing shell program
/ etc / passwd - developed to support the user's default shell program (/ sbin / nologin)
shell execution:
1, bash command to execute the script
- n view logic errors shell script (Note: the word may be wrong no matter) - the X-line display script execution (easy troubleshooting)
2, authorization chmod u + x filename.sh
Use the full path to execute the script, you can
3, variable
Environment Variables
Local variables declare command - Define variable type
Local variables local used in the function
Variable Types
Numeric:
1, plastic int
2, float float
3, boolean 0 1 (true false) (True False)
String:
1, ordinary characters and strings
2, array
Edit Categories languages:
Strongly typed language - values must be defined in order to make the True or False operation
A weakly typed language - programming language may automatically identify the type of variable
* * [Polymorphic data having a plurality of attributes, the properties depend on the final use of the data and its operation]
Parameter passing
$? - execute a command on the state of 0 correct 1-255 wrong
$ 1 $ 2 ... $ {10} - command script data passed back to the space as delimiter
$ # - Statistical pass parameters amount of $ {$ #}
$ * - indicates that all transmission parameters, all the parameters passed to the output string
$ @ - represents all the mass participation, all the parameters pass output in list form
[Work all the time to pass parameters to operate, we must consider $ * and $ @]
Define the variable format:
NAME = VALUE (intermediate no spaces)
We declare variables defined by the type of command
declare - i integer int () STR ()
DECLARE -a array
Variables command:
1, underlined specify the variable name
2, the command mode hump
4, test file test, the condition determination
In the script, we need to make the statement branch; it plainly, they do judge
Analyzing the test command is implemented;
Use judgment:
1、test [option] fine
2, [phrase condition]
Common test options:
Compare options:
-eq equal
-ne not equal
-gt greater than
-ge greater than or equal
-lt less than
-le less
Determine options:
-f determine whether a regular file
-d to determine whether the file directory
-L determine whether the linked file
-r -w -x determine whether the file has a read- write- execute permissions
Related options:
- o or
-a and
! non-
5, the logic operation
And &&: the command twice
Or ||
Non- ! =