shell_day03

Principles of Programming

1. Introduction to Programming

drive:

  1, the hardware default can not be used;

  2, the need for command communication between different hardware device manufacturers, we need drivers to "translate";

  3, more close to hardware development engineer, to learn "assembly language"; and "assembly language" is limited by the manufacturer; c c ++ is the underlying assembly language;

  Now based on high-level language programming, as well as ultra-high-level language, better enable programmers to implement programming

 

Programming languages ​​Category:

  High-level language, ultra-high-level language to be translated into computer-readable language (binary instructions)

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

     bash -x filename.sh line by line execution and output

  Compiled - once compiled, all of the implementation c language c ++ c # java

 

  Object-oriented - focusing on the data programming language

  Process oriented - focused on the programming language instructions

Programming language implementation:

  [] Line by line

  1, the order of execution

  2, the loop executes - * for (traverse) while (loop condition) an until (and while the opposite)

  3, choose to perform - Branch if case *

 

2.shell scripting language introduced

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

  Cons: no library calls (to distinguish python)

  shell scripts include:

    Command * (very important)

    Variables (the global variables, local variables, local variables, parameter passing)

    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 current session of the shell program

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

 

shell execution:

   1. bash command to execute the script

      -n View logic errors shell script (note: not a word wrong)

      -x Progressive script execution (easy troubleshooting)

   2. Authorized chmod u + x filename.sh

      Use the full path to the script execution

    

      if id $* &> /dev/null;then

        echo "The user already exists."

  else

     for i in $*;do

         useradd $i

      echo”123456”|passwd –stadin “$i” &>/dev/null

   done

     exit 0

  be

3. Variables

   Environment Variables

   Declare a local variable command - Define variable type

   Local local variables used in the function

   Variable Types

      Numeric: 1, int Integer

2, float type

3, 01 Boolean (true or false)

String: 1, ordinary characters and strings

Programming languages ​​Category:

  Strongly typed language - the value must be defined in order to process or operation

  A weakly typed language - programming language may automatically identify the type of variable

  [Polymorphism: a data having a plurality of attributes, properties depend on the final use of the data and calculation of his]

  Parameter passing

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

      $ 1 $ 2 $ {...} 10 incoming data command script later, a space for the separator

      $ # Amount of statistical parameters passed $ {$ #}

      $ * Means all transmission parameters, all the parameters passed to the output of string

      $ @ Means all transmission parameters, all the parameters output in the form of a list of

Define the variable format:

      NAME = value (without spaces, like a howl assignment, etc. howl two determination)

      We declare variables defined by the type of command

      declare -i integer

      declare -a array

 Variable name:

      Underlined specify the variable name

      Hump ​​naming

4.test file test, conditional

      In the script, we need to branch statement; it means making a judgment, judgment is to use the test command to achieve

Using the format:

  1. test[option]file

  2. [conditionals] Note: There are two spaces

Common test options:

     Compare options:

    -eq equal

    -ne not equal

    -gt greater than

    -ge and large

    -lt less than

    -le and small

     Determine options:

    -f determine whether a regular file

    -d whether the catalog file

    -L whether the linked file

    read -r -w -x write operation

     Associated option:! -O or -a with non

5. logic operation

     And && are true is true

     Or both have a really true ||

     non!

     The logical operator is present before and after the abutting a separate command

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

6. Arithmetic

     let 1+1

     expr 1*1

     $[$1+10]

     $(($1/$2))

     + - * / %

Guess you like

Origin www.cnblogs.com/TheNeverLemon/p/11347147.html