Created
June 5, 2010 01:24
-
-
Save meatballhat/426181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BANK_BALANCE="bank-balance" | |
MY_BALANCE="my-balance" | |
OUTSTANDING="outstanding" | |
function main(){ | |
local bank_bal=$(cat $BANK_BALANCE) | |
echo "bank balance = $bank_bal" | |
local my_bal=$(cat $MY_BALANCE) | |
echo "my balance = $my_bal" | |
local outstanding=$(_getsum $OUTSTANDING) | |
echo "outstanding = $outstanding" | |
echo -n "bank balance + outstanding = " | |
_dec_calc "$bank_bal + $outstanding" | |
local my_less_outstanding=$(_dec_calc "$my_bal - $outstanding") | |
check_my_balance $bank_bal $my_less_outstanding | |
return $? | |
} | |
function _getsum(){ | |
ret=0.00 | |
for amt in $(cat $1) | |
do | |
ret=$(_dec_calc "$ret + $amt") | |
done | |
echo $ret | |
} | |
function check_my_balance(){ | |
if [[ "$1" = "$2" ]] | |
then | |
echo "balanced!" | |
return 0 | |
else | |
echo "expected = $1" | |
echo "actual = $2" | |
echo "difference = $(_dec_calc "$1 - $2")" | |
return 1 | |
fi | |
} | |
function _dec_calc(){ | |
echo "scale=2; $*" | bc | |
} | |
main $* | |
exit $? | |
# vim:filetype=sh:fileencoding=utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim:fileencoding=utf-8 | |
CKBOOK := ./checkbooking | |
DATE := date | |
DEPS := bank-balance my-balance outstanding | |
last-done: $(DEPS) | |
$(CKBOOK) && $(DATE) > $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment