#fun.sh
#!/bin/bash
fun(){echo "making fun"
read -p "input a:" a
read -p "input b:" b
return $(($a + $b))
}
echo "=====begin====="
fun
echo "a+b=$?"
echo "======end======"
#fun2.sh
#!/bin/bash
fun(){
echo "the first:$1"
echo "the secend:$2"
echo "the tenth:${10}"
echo "the unknown number:$20"
echo "the all:$*"
echo "sum:$#"
echo "个数$#"
echo "参数集$*"
echo "当前进程id$$"
echo "最后一个进程id$!"
echo "分别参数集$@"
echo "shell使用的当前选项,和set相同$-"
echo "最后命令的退出状态$?"
}
echo "=====begin====="
fun 1 2 3 4 5 6 7 8 9 10 11
echo "||||||end||||||"
注意:
调用函数不需要后面加括号,传递参数直接加空格,在一行内完成输入。
$?是当前函数返回值