-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathque3.sh
More file actions
104 lines (97 loc) · 2.66 KB
/
que3.sh
File metadata and controls
104 lines (97 loc) · 2.66 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
show_welcome_screen() {
clear
echo "**** Welcome to My shellATM ****"
echo "**** Press any key to continue ****"
read -n 1
authenticate_user
}
authenticate_user() {
while true; do
echo -n "Enter your Card Number: "
read card_number
echo -n "Enter your Password: "
read -s password
echo
if grep -q "^$card_number, $password$" Credentials.txt; then
echo "Authentication done!"
list "$card_number"
break
else
echo "Invalid Card Number or Password. Please try again."
fi
done
}
list() {
card_number=$1
while true; do
echo "1. Withdraw cash"
echo "2. Deposit cash"
echo "3. Settings"
echo "4. Exit"
echo -n "Choose an option: "
read option
case $option in
1) withdraw_cash "$card_number";;
2) deposit_cash "$card_number";;
3) settings "$card_number";;
4) exit 0;;
*) echo "Invalid option. Please try again.";;
esac
done
}
get_balance() {
card_number=$1
grep "$card_number" Account.txt | awk -F', ' '{print $4}'
}
update_balance() {
card_number=$1
new_balance=$2
sed -i "/$card_number/ s/\(.*,\)\(.*\)$/\1 $new_balance/" Account.txt
}
withdraw_cash() {
card_number=$1
current_balance=$(get_balance "$card_number")
echo "Current Balance: $current_balance"
echo -n "Enter the amount to withdraw: "
read withdraw_amount
if [[ "$withdraw_amount" =~ ^[0-9]+$ ]]; then
if [ "$withdraw_amount" -le "$current_balance" ]; then
new_balance=$((current_balance - withdraw_amount))
update_balance "$card_number" "$new_balance"
echo "Withdrawal successful! New Balance: $new_balance"
else
echo "Insufficient balance."
fi
else
echo "Invalid amount. Please enter a non-negative number."
fi
}
deposit_cash() {
card_number=$1
current_balance=$(get_balance "$card_number")
echo "Current Balance: $current_balance"
echo -n "Enter the amount to deposit: "
read deposit_amount
if [[ "$deposit_amount" =~ ^[0-9]+$ ]]; then
new_balance=$((current_balance + deposit_amount))
update_balance "$card_number" "$new_balance"
echo "Deposit successful! New Balance: $new_balance"
else
echo "Invalid amount."
fi
}
settings() {
card_number=$1
current_email=$(grep "$card_number" Account.txt | awk -F', ' '{print $3}')
echo "Current Email ID: $current_email"
echo -n "Enter new Email ID: "
read new_email
if [[ "$new_email" =~ ^[a-zA-Z][a-zA-Z0-9]*@[a-z]+\.[a-z]+\.[a-z]+$ ]]; then
sed -i "/$card_number/ s/\(.*,\)\(.*\),\(.*\)$/\1\2, $new_email, \4/" Account.txt
echo "Email ID updated successfully!"
else
echo "Invalid Email ID format. Try again."
fi
}
show_welcome_screen