[~/shell/function]# cat factorial.sh
#!/bin/bash
function factorial
{
factorial=1
for (( i=1;i <= $1;i++ ))
do
factorial=$[ $factorial * $i ]
done
echo $1的阶乘是:$factorial
}
echo '程序名':$0,用于求阶乘
factorial $1
[~/shell/function]# ./factorial.sh 10
程序名:./factorial.sh,用于求阶乘
10的阶乘是:3628800
2.返回值