-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopping.sh
executable file
·53 lines (47 loc) · 1.03 KB
/
shopping.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
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
checkfun(){
column -t -s' ' tmpbill.txt
read -r
echo
}
costfun(){
read -rs quantity
cost=$(grep "$item" stock.txt | awk '{print $2}')
echo "$item $cost $quantity $((cost * quantity))" >> tmpbill.txt
totalAmount=$((totalAmount+(cost * quantity)))
}
showbillfun(){
column -t -s' ' tmpbill.txt
rm tmpbill.txt
echo
echo
echo "Total Amount = $totalAmount"
}
savebillfun(){
directory=$(date +%d%m%Y)
time=$(date +%H%M%S)
if [[ ! -d $HOME/billing/$directory ]];
then
mkdir -p "$HOME/billing/$directory"
fi
{ column -t -s' ' tmpbill.txt; echo; echo; echo "Total Amount = $totalAmount"; } >> "$HOME/billing/$directory/$time.txt"
}
touch tmpbill.txt
echo "Items MRP Quantity Total" >> tmpbill.txt
echo >> tmpbill.txt
totalAmount=0
while :
do
item=$(awk '{print $1}' stock.txt | fzf)
if [ "$item" = "exit" ]
then
break
elif [ "$item" = "check" ]
then
checkfun
else
costfun
fi
done
savebillfun
showbillfun