-
Notifications
You must be signed in to change notification settings - Fork 0
/
interest_calculator.sh
executable file
·43 lines (38 loc) · 1.35 KB
/
interest_calculator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#
# Author: Nate Levesque <[email protected]>
# Language: Shell
# File: interest_calculator.sh
#
# Description:
# A simple script to calculate interest on a bank account over a period
# of time. Optionally will also save the information to a file.
#
clear
echo "Interest calculation"
echo "Output to file?"
read -p "[Y]es or [N]o: " save_to_file
# Set up where "file" output goes, either /dev/null or an actual file
case "$save_to_file" in
"n"|"N")
outfile=/dev/null
;;
"y"|"Y")
read -p "Save where? (full path if not in running directory): " outfile
;;
esac
# Request the necessary information from the user
read -p "Starting Amount: $" P
read -p "Rate (decimal): " R
read -p "Times Compounded (in the period we're calculating): " N
read -p "Time in years: " T
# Formula is P(1+R/N)^(NT)
# Output the data and calculation to the console and the file (if saving)
echo "Starting amount: $P; Rate: $R; Times Compounded: $N; Time in years: $T;" > $outfile
echo "===========================================" | tee -a $outfile
echo "Resulting amount" | tee -a $outfile
echo "($P*e(($N*$T)*l(1+$R/$N)))" | bc -l | awk '{print ($1+0.00)}' | tee -a $outfile
echo "Gain" | tee -a $outfile
echo "($P*e(($N*$T)*l(1+$R/$N)))-$P" | bc -l | awk '{print ($1+0.00)}' | tee -a $outfile
echo "==========================================="
exit 0