shell script day07- function

   Function: Write code faster to repeated calls

A function of writing formats

 1. function check_cpu {

    CAT / proc / cpuinfo
    }
    LS / etc /
  check_cpu [not call the function, the function body command is not executed; where to invoke the function body in order to perform there]

    2.  *fun_name() {

    Function body
    $ 2 ... $ 10 $. 1
    }
  fun_name 2. 3. 1
: WQ
  function.sh. 4. 5. 6. 7. 9 10. 8 12 is 13 is 14. 11

  If the parameters can be used directly on the outside body of the function

Second, variable

  local local variables

  loacl i = 1

  If the function in vitro also defines a variable the same, does not take effect

  Extended: source / bash / chmod + x [full path of parent and child processes]

Three, return

  The end of the function body to perform

  And exit the difference

  return and exit are specified by the return value of 0 for successful execution, failed execution on behalf of 1-255

  return only for functions in the body;

Fourth, iterative

  Iteration must specify an initial value

Guess you like

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