#!/bin/bash
#===============================================================================
#
# FILE: calculator.sh
#
# USAGE: ./calculator.sh
#
# DESCRIPTION: Basically the bc command in -l mode with some extra functions defined
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: John Ryland (JR), (jryland@invertedlogic.com)
# COMPANY: InvertedLogic
# VERSION: 1.0
# CREATED: 21/05/2011
# REVISION: ---
#===============================================================================
LINE='
define factorial(x)
{
if (x <= 1)
return (1);
return (factorial(x-1)*x);
}
define combinations(x,y)
{
return factorial(x)/(factorial(y)*factorial(x-y));
}
define f(x)
{
return factorial(x)
}
define com(x)
{
return cominations(x)
}
'
while true
do
echo "$LINE"
read LINE
if [ "$LINE" == "quit" ]
then
exit
fi
done | bc -l