$? :用来获取函数返回值
[root@ipha-dev71-1 exercise_shell]# cat fun_with_return.sh
#!/bin/sh
funWithReturn(){
echo "这个函数会对输入的两个数字进行相加运算..."
echo "输入第一个数字:"
read aNum
echo "输入第二个数字:"
read anotherNum
echo "连个两个数字分别为$aNum和anotherNum"
return $(($aNum+$anotherNum))
}
funWithReturn
echo "两个数字之和为$?"
[root@ipha-dev71-1 exercise_shell]# chmod 777 fun_with_return.sh
[root@ipha-dev71-1 exercise_shell]# ./fun_with_return.sh
这个函数会对输入的两个数字进行相加运算...
输入第一个数字:
2
输入第二个数字:
3
连个两个数字分别为2和anotherNum
两个数字之和为5