forked from epety/100-shell-script-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path067-portfolio.sh
More file actions
executable file
·30 lines (24 loc) · 831 Bytes
/
067-portfolio.sh
File metadata and controls
executable file
·30 lines (24 loc) · 831 Bytes
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
#!/bin/sh
# portfolio - calculate the value of each stock in your holdings,
# then calculate the value of your overall portfolio, based on
# the latest stock market position.
getstock="sh 069-getstock.sh"
scriptbc="$HOME/bin/scriptbc"
portfolio="$HOME/.portfolio"
if [ ! -f $portfolio ] ; then
echo "$(basename $0): No portfolio to check? ($portfolio)" >&2
exit 1
fi
while read holding
do
eval $(echo $holding | \
awk -F\| '{print "name=\""$1"\"; ticker=\""$2"\"; hold=\""$3"\""}')
if [ ! -z "$ticker" ] ; then
value="$(eval $getstock $ticker)"
totval="$($scriptbc ${value:-0} \* $hold)"
echo "$name is trading at $value (your $hold shares = $totval)"
sumvalue="$($scriptbc ${sumvalue:-0} + $totval)"
fi
done < $portfolio
echo "Total portfolio value: $sumvalue"
exit 0