shell programming principles

Programming principle:
1, the programming is completed
    the drive hardware default can not be used
        CPU control hardware
        needed instruction communication between different manufacturers of hardware devices, drivers will need to be "translated"
        classification of programming languages:
            high-level language, ultra-high-level language needs translated into a computer readable language (binary instructions)
            interpreted - progressive translation, line by line the shell
                the bash filename.sh the -X-line execution
            of compiled - a compiler, all execution

            program instructions = + data
            Object-oriented - focusing the programming language of the data
            -oriented process - focus on command

        programming language implementation:
            1, the order of execution
                of a
            two cycle execution --FOR (traverse) while (loop condition) an until (and while the opposite)
            3, run the - branch if case

2, shell scripting language introduced
      advantages: Call os (operating system) command line to achieve all the features
      Cons: no library calls (to distinguish Python)

      shell scripts include: 1, command 2, the variable (global variables, local variables, pass parameters )
              3, the logic

      shell of the first sentence (to be written)
        #! / bin / bash-- defined script interpreter
        #! / usr / bin / Python

        / etc / shells-- view the current system to support the shell program
        echo $ SHELL - view the current shell program sessions
        / etc / passwd-- developed to support the user's default shell program (/ sbin / nologin)

        shell execution:
          1, bash command to execute the script
              -n see a shell script logic error (Note: the word may be wrong no matter)
              -x progressive script execution (easy troubleshooting)
          2, authorize chmod + x filename. sh
              using the full path to execute the script, you can

3, the variable
    environment variables to see and set env
    local variable declare command - Define variable type
    local variable used in the function of the local

    variable types:
        numeric:
          1. int Integer
          2. float a float
          3. Boolean 01 (true and false) (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 variables
        [polymorphic data having a plurality of attributes, the properties depend on the final use and it computation] data
        transmission parameters
            $? - on a command execution status 0 1-255 correct errors
            $ 1
            $ 2
            ...
            $ {10} - - {10} $ 1 $ incoming data following the command script, a space delimiters
            $ # - parameter statistic pass amount $ # $ {}
            $ * - indicates that all transmission parameters, all of the transmission parameters output as a string
            $ @ - represents a pass all the parameters, all the output parameter passing in a list of

          defined variable format:
            NAME = of VALUE (like a howl assignment, etc. howl Analyzing two)
            command defined variable types declare
            declare -ia = 10 integer int () STR ()
            declare arrays -a

          variables command:
            1. underlined specify the 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]
      common test options:
          comparison options:
            -eq equal
            -ne not equal
            -gt greater than
            -ge greater than or equal
            -lt less than
            -le less
          Analyzing options:
            -f whether ordinary file
            if the file exists -e
            -d whether directory file
            -L whether the linked file
            -r -w -x whether. . . Permissions
          associated option:
            -o or
            -a with
            ! Non-
5, logic operations
    And &&
    and ||
    non! =

    This logical operator, before and after docking commands are present alone
6, an arithmetic operation
    the let +. 1. 1
    the let A = +. 1. 1
    echo A $
    expr. 1 *. 1
    expr. 1 * 10
    $ [$. 1 +10]
    A = $ [. 3 + 2]
    echo $ A
    $ ((. 1 $ / $ 2))
    A = $ ((] 3/2))
    echo $ A

Guess you like

Origin www.cnblogs.com/wangzijie123456/p/11360533.html