#函数: Must be defined before using
#格式:
#function_name () {
# List of commands
# [return value] #可以显示增加return语句, if not added, the last command runs the result as a return #
#返回值只能是整数, generally used for function execution success or not, 0 for success, if return other #
#数据, you will be prompted numeric argument required#
#如一定要返回字符串, you can define the variables, receive the function calculation results, the script in the required #
#时候访问这个变量来获得函数返回值 #
#}
1 function Here 2 Function_hello () {3 Echo " "4}5function6 Function_hello # Calling the function only needs to give the function name without parentheses #
#带return语句的函数使用方法: Output: 30
1A=Ten2b= -3C= 'Expr${a} +${b} ' #单层替换命令函数方法 #4 Echo "${c}"5 function_sum () {6Return 'Expr${a} + ${b} ' or $ ((${a} +${b}))7 #$((....)) Multi-layer Substitution command function method, this method can only calculate the upper limit 255#8#两组括号的意思是做算术运算, if you do not write directly $a+ $b, press
#字符串理解的, that's it.20 This string9 }Ten Function_sum OneRet=$? #$?is to get the return value of the previous function # A Echo "${ret}"
#删除函数也可以使用unset命令, but add the. f option, as follows:
1 unset. F function_sum
#如果你希望直接从终端调用函数, you can define a function in the. profile file in the home directory,
#这样每次登录后, the terminal input function name can be used
#函数参数: The calling function can pass in the parameter and get the parameter value by ${n}, as follows:
1 function_num () {2 Echo "First parameter is ${1}"3 Echo "third parameter is ${3}"4 Echo "The amount of the parameter is ${#}"5 Echo " ${*} "6 }7Function_num1 2 5
Linux Gvim Shell functions