forked from m0zgen/countdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown.sh
More file actions
executable file
·79 lines (60 loc) · 1.44 KB
/
countdown.sh
File metadata and controls
executable file
·79 lines (60 loc) · 1.44 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
#!/bin/bash
# Use argument for count down. Example: ./countdown.sh 10
# Author: Yevgeniy Goncharov aka xck, http://sys-admin.kz
# Help information
usage() {
echo -e "" "\nParameters:\n"
echo -e "-c - Count (in seconds)"
echo -e "-f - Format (1 - Every line, 2 - One Line)\n"
exit 1
}
countdown_by_line() {
if [[ ! $1 ]]; then
echo "Please set countdown. Exit."
exit 1
else
secs=$1
fi
# bash while loop
while [ $secs -gt 0 ]; do
echo $secs
let secs=secs-1
sleep 1
done
echo Finish!
}
countdown_one_line() {
# secs=$((5 * 60))
if [[ ! $1 ]]; then
echo "Please set countdown. Exit."
exit 1
else
secs=$1
fi
# bash while loop
while [ $secs -gt 0 ]; do
echo -ne "$secs\033[0K\r"
sleep 1
: $((secs--))
done
echo Finish!
}
if [[ -z "$1" ]]; then
usage
exit 1
fi
while [[ "$#" -gt 0 ]]; do
case $1 in
-c|--count) COUNT=$2; ;;
-f|--format) FORMAT="$2"; shift ;;
-h|--help) usage ;;
esac
shift
done
if [[ "$FORMAT" -eq "1" ]]; then
countdown_by_line $COUNT
elif [[ "$FORMAT" -eq "2" ]]; then
countdown_one_line $COUNT
else
echo "Unknown format. Exit. Bye!"
fi