#!/bin/bash
function generalista ()
{
if [ $1 == "0" ] || [ $1 == "1" ]
then
echo 1
else
VARF=$(($1-1))
echo $VARF
generalista $VARF
fi
}
if [ "$#" == "1" ]
then
if [ $1 -ge 0 ]
then
time LISTA=$(generalista $1)
echo El factorial es el producto de los factores de esta lista : $LISTA
FACTORIAL=1;
for FACTOR in $LISTA
do
TEMP=$(($FACTORIAL*$FACTOR))
FACTORIAL=$TEMP
done
echo Entonces, el factorial de $1 es $FACTORIAL, aunque eso no es correcto...
else
echo Error: integer MUST be positive
fi
else
echo Usage: $0 positive_integer
fi
2005/02/16
High leveling common tools
Tools like bash worths a "man bash" reading. You can even make recursive scripts! Lets play...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment