Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a bash script named “MyWallet.sh” managing a simple bill system. Every bil

ID: 3682390 • Letter: W

Question

Write a bash script named “MyWallet.sh” managing a simple bill system. Every bill corresponds to a record (line) in a text file named “bills.txt” (if this file is inexistent, create it). Each record consists of 7 fields (record ID, category, detail, amount, year, month, day) separate by percent sign (%).

e.g.: 1%restaurant%subway%5.58%2016%2%11 2%gas station%shell%20.15%2016%3%1

• No percent sign (%) in each field.

• The “record ID” is unique, and generated by this system automatically. (when create a new record, the ID should be the last record’s ID number + 1.)

• The category, detail, and amount are input by user.

• The date (year, month,day) is generated by this system by using the record creation time. (Year: date “+%Y” ; Month: date “+%m” ; Day: date “+%d”)

• MyWallet.sh should provide a menu with following functionalities that users can choose from at the top level menu:

1. Enter “a” to add a new bill

• Ask for category

Ask for detail

• Ask for amount

• Generate record ID and date

• Add this new record into “bills.txt” file

• At the end, print “New bill added successfully”

• Provide option “t” for “Try again” and “b” for “Back to main menu”

2. Enter “d” to remove a bill

• Ask for record ID

• Examine if this record exits. if no, print a message “No such record!”, otherwise, display this record and remove it from “bills.txt” file.

• Provide option “t” for “Try again” and “b” for “Back to main menu”

3. Enter “c” to count amount

• Ask for time range (start date(year, month,day) and end date(year,month,day))

• Count and display amount of all bills in this time period.

• Provide option “t” for “Try again” and “b” for “Back to main menu”

4. Enter “v” to view bills

• Ask for search type (by category, by time, or by record ID)

• Ask for category if by category

• Ask for time range if by time

• Ask record ID if by record ID • Display all bills satisfied the condition

• Provide option “t” for “Try again” and “b” for “Back to main menu”

5. Enter “q” to quit this system

• Terminate this system

Explanation / Answer

clear

i="y"

var=1

total=0;

FILE = "bills.txt"

while [ $i = "y" ]
do
clear
echo "Enter “a” to add a new bill "
echo "Enter “d” to remove a bill "
echo "Enter “c” to count amount "
echo "Enter “v” to view bills "
echo "Enter “q” to quit this system"
echo "Enter your choice "
read ch
case $ch in
a)$cat FILE >> copy_FILE;;
  
echo "Enter category: "
read cate
  
echo "Enter detail: "
read deta   
  
echo "Enter amount:"
read amount

now = "$(date+'%d/%m/%Y')"

echo "$var $cate $deta $amount $now">> $FILE ;;
  
let "var++"

d)echo "Enter Id"
read id
# set -a
# sed '/$id/d' $FILE>dbs1
grep -v "$id" $FILE>dbs1
echo "Record is deleted"
cat dbs1;;
  
c)echo "Total amount: $total"
  
v) start_date = $(date +'%d/%m/%Y')

end_date = $(date +'%d/%m/%Y')

read -p "Enter start date (dd-mm-yy): " start_date
read -p "Enter end date (dd-mm-yy): " end_date

cat FILE | while [$ch = "t"]
do
if [$now == $start_date -ge $now == $end_date];

total = 'expr $amount + $total'
echo "Try it again by press t"
echo "Back to menu press b"
read c
case $c in
t) ch = "c"
b) i = "y"

q)exit;;
  
*)echo "Invalid choice ";;
esac
echo "Do u want to continue ?"
read i
if [ $i != "y" ]
then
exit
fi
done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote