Programming principle:
1, Introduction to Programming
early language:
Drive hardware default can not be used;
the need for command communication between different hardware device manufacturers, we need to drive to "translate";
more close and hardware development engineers, to learn "assembly language"; and "assembly language" is limited by the manufacturer; C C ++ language is the underlying assembly language;
Now programming:
Based on high-level language, as well as ultra-high-level language, better enable programmers to achieve programming;
classification of programming languages:
high-level language, ultra-high-level language to be translated into computer-readable language (binary instructions)
Interpreter - progressive translation, the JAVA Python line execution the shell
the bash the -X-filename.sh
compiled - a compiler, performs all the C language C ++ C # JAVA
program instructions = + Data
Object-oriented - focusing on the data programming language
Process for - focus on instruction
implementation programming language:
[] line by line
1, the order of execution
2 repeatedly executed - * for (traversing) * while (loop condition) an until (and while the opposite)
3, choose to perform - a branch if * case *
2, shell scripting language introduced
advantages: Call os (operating system) command line to achieve all functions;
Disadvantages: No library calls (to distinguish Python)
shell scripts include: 1 * command * () 2, variable (global variables, local variables, local variables, parameter passing) 3, logic
shell first sentence! ! ! (Must be written)
#! / bin / bash - defined script interpreter (# is generally considered a comment line, where special) the shebang
#! / user / bin / python
/ etc / shells - to view the current program supported by the system shell
echo $ SHELL - shell program to check the current session of the
/ etc / passwd - developed to support the user's default shell program (/ sbin / nologin)
shell execution:
1, bash command to execute the script
-n view the shell script program logic error (Note: the word may be wrong no matter)
-x progressive script execution (easy troubleshooting)
2, authorize chmod u + x filename.sh
use the full path execute the script, you can
3, variable
Environment Variables
Local variables declare command - Define variable type
local variable used in the function local
variable types:
numeric:
1, shaping int
2, float a float
. 3, the Boolean value 0 1 (true false)
String:
1, ordinary characters and strings
2, array
Classification of programming languages:
a strongly typed language - the value must be defined in order to carry out the processing operation or
a weakly typed language - programming language may automatically identify the type of variable
[* * polymorphic data having a plurality of attributes, attribute depends on the final use of he and data in operation]
Parameter passing
$ -? A command execution status 0 1-255 correct errors
$ 1 $ 2 $ {...} 10 - incoming data command script later, a space for the separator
$ # - Traditional pass the parameter amount } {$ # $
$ * - indicates that all transmission parameters, all the parameters passed to output string
$ @ - represents a pass all the parameters, all the parameters passed in the form of a list of output
[to work All parameter passing operating time, we must consider the $ * and $ @]
Variables defined format:
NAME of VALUE = (equal to a call assignment, etc. howl Analyzing two)
we declare variables define the type of command to
declare 10 -ia = int () STR ()
declare -a array
variable command:
1, underlined specify variable name
2, hump naming
4, test file test to determine the conditions
in the script, we need to make the statement branch; it plainly, is to do judgment
judgment is to use the test command to achieve;
using the format:
1, test [the Option] File
2, [conditional statement]
[ teacher, when added [] when not to add []? ]
Common test options:
comparison options:
-eq equal
-ne not equal
-gt greater than
-ge greater than or equal
-lt less than
-le Less than or equal
to determine options:
-f to determine whether a regular file
-d to determine whether the catalog file
-L determine whether for the linked file
-r -w -x determine whether the rights
associated option:
-o or
-a with
! non-
Analyzing String:
= Analyzing the strings are equal on both sides
! = Not equal
-z string is determined whether the presence
-n -z and Rather, there is false, there is no true
5, logic operations
with &&: both sides of the commands are true, the result was true
|| or: command on both sides, one side is true, that is true, but false, is false
non =!
The logical operator command before and after docking is present alone;
[$ 0 -eq?] 0 && Exit Exit. 1 ||
6, the arithmetic operation
the let +. 1. 1
the let A = +. 1. 1
echo A $
expr. 1 *. 1
expr. 1 * 10
$ [10 + $. 1]
a = $ [2 + 3]
echo $ a
$ (($ 1/2))
a = $ ((3/2))
echo $ a
+ - * / % **