#!/bin/bash
# fact.sh - Shell script to to find factorial of given command line arg
factorial () {
local i = $1
local f
declare -i i
declare -i f
# factorial() is called until the value of $f is returned and is it is <= 2
# This is called the recursion
[ $i -le 2 ] && echo $i || { f = $(( i - 1 ))
f = $( factorial $f )
f = $(( f * i ))
echo $f ; } }
# display usage [ $# -eq 0 ] && { echo "Usage: $0 number" ; exit 1 ; }
# call factorial
factorial $1
Save and close the file. Run it as follows:
chmod +x fact.sh ./fact.sh ./fact.sh 2 ./fact.sh 5
#!/bin/bash
# fact.sh - Shell script to to find factorial of given command line arg
factorial () {
local i = $1
local f
declare -i i
declare -i f
# factorial() is called until the value of $f is returned and is it is <= 2
# This is called the recursion
[ $i -le 2 ] && echo $i || { f = $(( i - 1 ))
f = $( factorial $f )
f = $(( f * i ))
echo $f ; } }
# display usage [ $# -eq 0 ] && { echo "Usage: $0 number" ; exit 1 ; }
# call factorial
factorial $1
Save and close the file. Run it as follows:
chmod +x fact.sh ./fact.sh ./fact.sh 2 ./fact.sh 5
| status | not learned | measured difficulty | 37% [default] | last interval [days] | |||
|---|---|---|---|---|---|---|---|
| repetition number in this series | 0 | memorised on | scheduled repetition | ||||
| scheduled repetition interval | last repetition or drill |