一、函数定义:
(1)定义:
# []:可选
[function] funcname(){
函数体
[return var]
}
(2)函数无参数演示
function func1(){
echo "我是自定义函数"
}
# 调用函数
func1
(3)函数返回值
ret(){
a=1
b=2
sum=$((a+b))
return $sum
}
ret
echo "return value: $?"
(4)函数带参数
params(){
echo "参数1: $1"
echo "参数2: $2"
echo "参数3: $3"
echo "参数4: $4"
echo "参数5: $5"
echo "参数6: $6"
}
params 1 2 3 4 5 6