function1. Role1call a piece of code repeatedly2) to categorize the code snippets.2. Set function name () {Body of code}3. Function name4. Return value using $?viewing the return value of 0 represents the correct, non-0 representation of the incorrect. The return value of the function refers to the value that needs to be returned to the caller after the function ends. Use return to follow the numbers to specify the return value5The position parameter of the function refers to the first argument passed to the function, and the second argument is passed to the function. Fun () {Echo$1 Echo$2 Echo$3}result=$ (Fun1 2 3)Echo$result [[email protected]~]# bash CANSHU1.SH 1 2 36. Example #!/bin/bashshell_like () { Case$1 inchYes) return0 ;; NO) return1 ;; *) return1 ;; Esac}# forIinch{1.. About}# DoRead-P"does u like shell?"RepifShell_like"$rep" Then Echo "Me,too"&&ExitElse Echo "input Error,retry"fi# Done7global variables and local variables. Global variable: is a variable local variable that is valid for all contents of a script: is the definition of a local variable that is only valid for code snippets within a function locally a=1title: Bash xxxx.SHInput-T5represents a triangle with 5 lines of paint-L7represents a draw slash 7 lines #!/bin/Bashtriangle () { forXinch$(seq 1$1) Do forYinch$(seq 1$(($1-$x))) Do Echo-N" " Done forZinch$(seq 1$((2* $x-1))) Do Echo-N"&" DoneEcho Done}line () { forIinch$(seq 1$1) Do forXinch$(seq 1$i) Do Echo-N" " DoneEcho-N"^"Echo Done} Case$1 inch-t) TRIANGLE" $" ;; -l) Line" $" ;;Esac~
0 Basic Learning Cloud computing and Big Data DBA cluster Architect "Linux Bash shell Programming and system Automation January 13, 2015 Wednesday"