格式:
[function] fun() {
action;
[return int;]
}
eg:
[root@k8s-master test7]# cat t0.sh
#!/bin/bash
fun() {
echo 'helloworld'
}
echo 'start...'
fun
echo 'end...'
[root@k8s-master test7]# ./t0.sh
start...
helloworld
end...
[root@k8s-master test7]#
[root@k8s-master test7]# ./t1.sh
input 1st num:
1
input 2st num:
2
n1=1 and n2=2:
sum is: 3
[root@k8s-master test7]# cat t1.sh
#!/bin/bash
s() {
echo 'input 1st num:'
read n1
echo 'input 2st num:'
read n2
echo "n1=$n1 and n2=$n2:"
return $(($n1+$n2))
}
s
echo "sum is: $?"
[root@k8s-master test7]#
[root@k8s-master test7]# ./t3.sh
first: 1
sencod: 2
11th: 11
total: 12
[root@k8s-master test7]# cat t3.sh
#!/bin/bash
f() {
echo "first: $1"
echo "sencod: $2"
echo "11th: ${11}"
echo "total: $#"
}
f 1 2 3 4 5 6 7 8 9 10 11 12
[root@k8s-master test7]#