#!/bin/bash
# example 1: no return value, no parameter
# define function
demoFun(){
echo "this is first shell function!"
}
# run function
demoFun
#example 2: has return value and parameter
funWithReturn(){
echo "this function will get the sum of the two number"
echo "please input the first number:"
read fstNum
echo "please input the second number"
read sndNum
echo "two number are: $fstNum and $sndNum"
return $(($fstNum+$sndNum))
}
# run function
funWithReturn
echo "sum of these number is : $?"
#函数返回值在调用该函数后通过 $? 来获得