8-13 Principles of Programming

Programming principle:
1, Introduction to Programming
early Programming:
drive hardware default can not be used;
the need for command communication between different hardware device manufacturers, we need drivers to be translated
more close and hardware development engineers, to learn "compilation language "; and the assembly language is limited by the manufacturers; the underlying C C ++ is the assembly language;
now programming:
based on high-level language, as well as ultra-high-level language, better enable programmers to implement programming

Classification of programming languages:
high-level language, ultra-high-level language to be translated into computer-readable language (binary instructions)
interpreted - translated line by line, line by line JAVA Python shell
bash -x filename.sh
compiled - once compiled, Full implementation of C language C ++ C # JAVA

Program instructions = + Data
Object Oriented - focus on the data programming language
oriented process - focus on instruction

Programming language implementation:
[] line by line
1, the order of execution
2, loop execution - for (traversing) while (loop condition) an until (and while the opposite)
3, choose to perform - to focus on instruction

2, shell scripting language introduced
drawback: shell no built-in functions, there is no function library calls
advantages: Calling os operating system command line to achieve all the features

shell script comprising: a command ()
2, variable (global variables, local variables, local variables, parameter passing)
3, logic

shell first words! (Must be written)
# / bin / bash (# called Shebang!) -! Custom script interpreter (# is generally considered a comment line, where special)

CAT / etc / shells to view the current program supported by the system shell
echo $ SHELL View shell program for the current session of the
/ etc / passwd specifies the user's default shell program support

shell execution:
1.bash command to execute the script
-n see a shell script logic error (Note: the word wrong no matter)
-x Progressive script execution (easy troubleshooting)
2. Authorizes the chmod + x filename.sh
use the full path to the script execution


3, variable (section named memory space for storing temporary)
Environment Variables
Local variables declare - Define variable type
local variable used in the function local

variable types:
numeric:
1, plastic int (numeric overflow)
2, floating point type float (overflow more serious)
3, boolean 01 (true and false) (True False)
string:
1, ordinary characters and strings
2, array

Classification programming language:
The variables, into a strongly typed language, and a weakly typed language
1, strongly typed language - the value must be defined in order to be processed or operation
2, a weakly typed language - programming language may automatically identify the type of variable
Chiefly state: a data having a plurality of attributes, the properties depend on the final use of the data and its operation]

Parameter passing
execution state (0 right, wrong 1-255) $? Command on a
$ 1 $ 2 $ .. {10} incoming data after the command script, as a space separator
$ # {$ amount statistic parameters passed $ # } ()
$ * represents all output parameters to pass a string
$ @ represents all output parameters to pass in a list of
defined variable format
NAME = VALUE
by variable type defined declare
declare -i represents an integer
declare -a array representing
variable name:
1, underlined the way to develop the variable name
2, hump naming

test file test, to determine the conditions
in the script, we need to make the statement branch; it plainly, is to be done to determine
judge is to use the test command to achieve;
using the format:
1.test [the Option] File
2. [conditionals]
common test options:
comparison of options:
-eq equal
-ne not equal
-gt greater than
-ge greater than or equal
-lt less than
-le small and equal to
judge options:
whether the judge -e file exists
-f to determine whether a regular file
-d to determine whether the file directory
-L determines whether the link file
-r -w -x (whether the file has permission to execute read and write)
the associated options:
-o (or)
-a (and)
! (non)
string determination:
= both sides of the string is determined are the same
! Is not equal to
-z STRING a string of 0 is true
-n -z and Rather, there is false, there is no true
5, logical operations
and &&: command sides are true, the result is true
or ||: any while the command is true, the result is true for both false, is false
non-! =

the logical operators around the butt of all there is a separate command

[ $? -eq 0 ] && exit 0 ||exit 1

6, math运算
Let 1 Tasu 1
Let A = 1 Tasu 1
Echo $ A
Expr 1 * 1
Expr 1 * 10
$ [$ 1 Tasu 10]
A = $ [2 Tasu 3]
Echo $ A
$ (($ 1 / $ 2))
= $ A (3/2)
Echo $ A

Operators: + - * / **%


! # / bin / bash
# Add the user
IF the above mentioned id * $ &> / dev / null; the then
  echo "The user already exists"
the else
  for i in $ *; do
    useradd $ i
    echo "123456" | passwd --stdin "$ I "&> / dev / null
    echo" user added successfully $ i "
  DONE
  Exit 0
Fi

 

Guess you like

Origin www.cnblogs.com/liuyuanzzz/p/11347447.html