Friday, October 16, 2009

[Shell script] 遞迴

#!/bin/bash
function re () {
local tmp
tmp=$1
if [ $tmp -eq 1 ]; then
total=1
else
re $(($tmp-1))
total=$(($tmp*$total))
fi
}


read -p "Data=" VAR
re $VAR
echo "$VAR!=$total"
太久沒寫了腦袋打結了一下。

No comments: