Xshell learning Lesson 3: Principles of Programming

 

  1. Introduction to Programming

Drive: hardware default can not be used (cpu control hardware) provided by different manufacturers ah need to command the communication between hardware devices, drivers we need to "translate";

More close to engineer hardware development, to learn assembly language; assembly language is limited and manufacturers

Computers can only binary instruction

Program instructions = data +

Depending on the service center of gravity, we divided into process-oriented programming and object-oriented programming

Process focusing on the instruction for >>>>>>

Focusing on the object-oriented data >>>>>>

Depending on the program translated into binary instructions the way, high-level language into low-level languages

Low-level language: assembly language

High-level language: ultra-high-level language and high-level language need to 'translate' into computer-readable language

Interpreted - translated line by line, line by line: shell python

Bash -x filrname.sh

          Compiled: - once compiled, all of the implementation of C language, C ++, C #

Implementation of programming languages: [line by line]

           1, the order of execution

2. The loop executes -for while unitl (and while the opposite)

                   3. Select the execution - Branch if case *

  1. Shell scripting language introduced

Shell statement is process-oriented, focusing on the instruction set;

The basic structure of the Shell statement consists of:

  1. command
  2. ---- data variables (the 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 program supported by the system shell

--echo $ SHELL - view the shell program for the current session

/ Etc / passwd - developed to support the user's default shell program (/ sbin / nologin)

Shell execution:

       --bash command to execute the script

                   -n View shell script logic errors (note that the word can be wrong no matter)

                   -x Progressive script execution (easy troubleshooting)

       - Authorization shmod + x filename.sh

                    Use the full path to execute the script, you can

    Shell is no built-in functions, no library calls

     Advantages: call the command line os operating system, to implement all functions;

     Cons: no library calls (to distinguish python)

 

  1. variable

Environment Variables

Declare a local variable command - Define variable type

Local local variables used in the function

 Variable type:

      Numeric: plastic (int), floating point (float), Boolean values ​​(True, False)

      String: ordinary characters and strings, arrays

Programming languages ​​Category:

Strongly typed language - definition must be defined in order to process or 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 and operation of his data]

Parameter passing:

      $ -? Command execution status of 0 on a 1-255 correct errors

      $1  -----

      $ 2, ---- script command behind the incoming data, a space-delimited

      ${10} -----

      $ # ----- statistical parameters passed amount of $ {$ #}

      * $ ---- represents all transmission parameters, all of the transmission parameters output as a string

      $ @ --- represents all the mass participation, mass participation of all output in tabular form

[Work all the time to pass parameters to operate, we must consider and $ @ $ *]

Define the variable format:

       NAME=VALUE

We declare variables defined by the type of command

--declare -i(整数) a = 10 int() str()

--declare -a (array)

Variable name:

  1. Underlined specify the variable name
  2.  Hump ​​naming
  3. Test test file, conditional

In the script we need to branch statement; it plainly would do judgment, and judgment is to use the test command to achieve;

Using the format:

          1.test [option] file

          2. [conditionals]

Common test options:

- Comparison of Options: -eq equal

            -ne not equal

            -gt greater than

            greater than or equal -ge

            -lt less than

            -le less

- determine options: -f to determine whether a regular file

            -d to determine whether the file directory

            Determining whether the connection file -L

            Determine whether -r -w -x file has execute permissions to read and write

- associated option: -o or

            -a and

             ! non-

- Analyzing string:

            = Determined even if the same side of the string

            ! = Not equal

            -Z string is determined whether the presence of

            -n and -z Rather, there is false, there is no true

  1. logic operation

And &&: command both sides, are true, the result is true

Or ||: both sides of the command, while true, is true, and false is false

Non-! =

The logical operator commands are present in the individual before and after docking;

 

  1. Arithmetic

        *let 1+1

        --expr 1*1

        *$[$1+10]

        $(($1))

 

Guess you like

Origin www.cnblogs.com/huangchuan/p/11348380.html