Basic introduction to shell script

1, Introduction to Programming
  drive hardware default can not be used
  CPU control hardware, the need for command communication between different hardware device manufacturers, we need drivers to "translate";
  more nearly and development engineer, to learn "assembly language "; and" assembly language "is limited by the manufacturers;
  the underlying C C ++ assembly language is
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)
  interpreted - translated line by line execution, the Java Python shell
  bash -x filename.sh
  compiled --- once compiled, all of the implementation of C language C ++ C # java
  program instructions = + data
  Object-oriented programming languages --- focus data
  for the process to focus on instruction ---
  implementation programming language:
    1, the order of execution
    2 repeatedly executed for (traverse) the while (loop condition) until (while the opposite)
    3, --- choose to perform branch if case

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

  shell script include: 1. 2. Command variables (global variables, local variables, local variables, parameter passing) 3 logic

  · shell of the first sentence
  ! # / Bin / bash - - define the script interpreter

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

  execute the shell:
  1, bash command to execute the script
  logic errors -n View shell script
  -x progressive display script execution
  2, chmod + x filename.sh authorized to
  use the full path to the script execution

 

3, the variable
  environment variables
  local variables DECLARE: Define variable type
  local variable used in the function local

  variable types:
    numeric:
    1. int Integer
    2. float a float
    3. Boolean 01 (Ture True False False)
  string :
    1. Common character strings and
    2. the array of

   classification of programming languages:
    a strongly typed language - the value must be defined in order to be processed or operation
    weakly typed language - programming language may automatically identify the type of variable
    (polymorphic data having a plurality attribute, and the attribute depends on his last used for computing data)
    transmitted parameters
      $ -? a command execution status 0 1-255 correct errors
      $ 1 $ 2 $ .. {10} - command script later break data, a space for the separator
      $ # - the number of statistical parameter passing
      $ * - indicates all parameter passing, pass all parameters transmitted in the form of a string
      $ @ - represents a pass all the parameters, all the parameters passed output in the form of a list of

   Defining the variable format:
    NAME = value = Assignment == Analyzing
    declare type defined parameters
    declare -i integer
    declare -a array of
    variable names:
      1. The underlined variable names specify
      2. camelCasing embodiment
  
4, test file test condition is determined
  in script, we need to branch statement, you need to test to determine achieved

    using the format:
    1.test [the option] File
    2. [conditionals] before and after the conditional statements spaces!

   common test options:
      comparison options:
        -eq =
        -ne
        - gt>
        -ge> =
        -LT-<
        -le <=
    Analyzing options:
        -f determining whether a regular file
        -d determines whether the directory file
        -L determines whether the connection file
        -r -w -x determines whether the read execution file permissions
    associated option:
        -o or
        -a with
        ! Non-
    characters determination:
        = determining whether the same string
        = not equal!
        -Z string is determined whether the presence
        -n -z and the opposite

5, logical operations
    and - command && sides are true, the result is true
    or - || two side edges command is true. The result is true, as well as false, the result is false
    non -! =

    The logical operators, are there separate command before and after docking

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

6, arithmetic
      let 1 + 1 

          let a =1+1

          echo $ a

      expr 1+1

          let a =1+1

          echo $ a

      $[$1+10]

           a=$[2+3]

          echo $ a

      $(($1/$2))

           a=$((3/2))

          echo $ a

Guess you like

Origin www.cnblogs.com/liu694233527/p/11347409.html