fact() {
if[$1-eq1]
then
echo 1
else
local temp=$[$1 - 1]
local result=$(fact $temp)
echo $[$1 * $result]
# 5 * $result (4*$result(3*$result(2*$result(1))))
fi
}
read -p "请输入: " n
result=$(fact $n)
echo $resul
递归目录
function list_files {
for f in `ls $1`
do
if [ -d "$1/$f" ]
then
echo "$2$f"
list_files "$1/$f" "$2"
else
echo "$2$f"
fi
done
}
list_files "/var/log" ""
创建库
vim myfuncs.sh
jiafa() {
echo $[$1 + $2]
}
chengfa() {
echo $[$1 * $2]
}
chufa() {
if [ $2 -ne 0 ];then
echo $[$1 / $2]
else
echo "$2不能为0"
fi
}
vim test.sh
. myfuncs.sh