-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.sh
50 lines (38 loc) · 1017 Bytes
/
delete.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
#!/bin/bash
cd /backup # location of the backups
echo -e "\n---------------------------------------------------------------------------------\n"
echo -e "What folder do you wanna delete ?\n"
files=$(ls -d)
i=1
for j in $files
do
echo "$i.$j"
file[i]=$j
i=$(( i + 1 ))
done
echo -e "\n---------------------------------------------------------------------------------\n"
echo -e "Enter number\n"
read input
re='^[0-9]+$'
while :; do
if ! [[ $input =~ $re ]] ; then
if [ "$input" == "l" ] || [ "$input" == "exit" ] || [ "$input" == "q" ]; then
echo "This script will exit now."
exit 1
else
echo "Error: Not a number"
echo -e "Enter number"
read input
fi
else
break
fi
done
read -r -p "Please insert 'YES' to allow the deletion. Otherwise this script will exit here: " ANSWER
if [ "$ANSWER" == "YES" ] || [ "$ANSWER" == "y" ]; then
echo "Deleting the folder..."
rm -r ${file[$input]}
else
echo "Your answer was \"$ANSWER\" and not YES. So this script will exit now."
exit 1
fi