shell script programming principles day03-

I. Introduction to Programming

  (Computers can only binary instructions)

  1.   Early Programming: drive and hardware default can not be used, but requires instruction communication between equipment from different vendors, we need to drive to be translated; more tight and hardware development engineers, to learn assembly language, assembly language and is limited by the manufacturers. C, C ++ is the underlying assembly language
  2. Now based on high-level language programming, as well as ultra-high-level language, better enable programmers to implement reporting functionality. High-level language, ultra-high-level language to be translated into computer-readable language (binary instructions)
  3. Assembler Language Category
    • Interpreted --- progressive interpretation, line by line shell python java
    • Compiled --- once compiled, all the lines C C ++ C # java
    • --- Object-oriented programming languages ​​focus on data
    • Process for the focus on instruction ---
  4. Programming language implementation:

      [Executive] row

    • Order execution
    • --- for loop execution (traverse) while (loop condition) an until (and while the opposite)
    • --- choose to perform branch if case

Two, shell scripting language introduced

  shell statement is process-oriented, focusing on the instruction set.  

  Advantages: call the command os (operating system) of the line to all the functions;

  Cons: no library call (distinguished from python)

  The basic components of shell statements:

    • Command (emphasis!)
    • Variables (the global variables, local variables, local variables)
    • Logic
    • Data - variable (rotation reference)

  no shell built-in functions, no library calls, no calls to the library interfaces

Three, shell first sentence (important)

  

#! / bin / bash // define script interpreter (# is generally considered a comment line, where special) 
#! / usr / bin / Python

 / etc / shells // view the current program supported by the system shell 
echo $ shell   // View the current session of the shell program 
/ etc / passwd  // specify the shell program before the user's default (/ sbin / nologin)

  shell execution:

    1. bash command to execute the script
      • -n View logic errors shell script (note: the word wrong can not be viewed)
      • -x Progressive script execution (easy troubleshooting)

       2. Authorizes chmod u + x filename.sh

        Use the full path to execution

Fourth, the variable (some unnamed memory space)

  1. Environment Variables
  2. --- declare local variables defined command variable types
  3. Local local variables used in the function  
  4. Variable Types
    • Numeric
      • Plastic Int
      • Float float
      • Boolean value true false 0 1
    • String
      • Ordinary characters and strings
      • Array
    • Classification of programming languages
      • Strongly typed language --- value must be defined in order to process or operation
      • Programming language can automatically identify the type of variable

      NOTE: Polymorphism: a data having a plurality of attributes, the properties depend on the final use of the data and its operation

  5. parameter passing

    • $? Execute a command on the state --- 0 1-255 correct errors
    • $ 1 $ 2 $ {...} 10 --- incoming data command script later, a space for the separator
    • $ # --- Number of statistical parameter passing $ {$ #} // this command is to take the last argument
    • $ @ --- represents all the mass participation, mass participation of all output in the form of a list of
    • $ * --- represents all the mass participation, mass participation of all output in the form of a list of
    • Work should be considered in $ @ $ * difference

  6. Define Variable Format

    • NAME = VALUE (like a howl assignment determines both a howl etc.)
    • Declare the variable type is defined by the command
    • -la = DECLARE 10   // corresponds int () 
      DECLARE -a // Array
        

  7. There are two ways to variable naming, respectively, to underscore the manner specified variable names and to naming names hump

Five, test file test, conditional

  In the script, we need to branch statement, simply put, it is to judge, and judge is to use the test command to achieve

  1. Use the format

    • test[opthon]file
    • [Conditionals] // must join the two spaces within the brackets

  2. Common test options

Compare Options -eq equal -ne not equal -gt greater than greater than or equal -ge -le less -lt less than
Judgment Options  -f determine whether a regular file -d to determine whether the file directory -l determine whether the sequential file  -Rwx determine whether the file has execute permissions to read and write
Association Options -0 or -a and ! Non -
Analyzing string = Determining whether the string is equal to both sides ! = Not equal -Z string is determined whether the presence of -n and -n opposite effect

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Six, arithmetic and logic operations

  And: &&; or: ||; non-:!

  let !+1

  expr 1*1

  $[$1+10]

  $(($1/$2))

   

    

Guess you like

Origin www.cnblogs.com/ljx1/p/11348182.html