-
Notifications
You must be signed in to change notification settings - Fork 0
/
count_down
executable file
·56 lines (50 loc) · 1.17 KB
/
count_down
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
#!/usr/bin/env bash
set -eu
#######################################
# Function: Countdown (default is numbers)
# Parameters:
# -n: Output numbers for countdown
# $1: Number of seconds
# Output:
# 3 2 1 0 or ....
#######################################
function print_usage() {
echo 'Usage:'
echo ' count_down -n [seconds]'
echo " -n print number"
echo ''
echo "Examples:"
echo " count_down 3"
}
#######################################
# flags
declare use_number='false'
declare option
while getopts nh option; do
case $option in
n) use_number='true' ;;
h) print_usage; exit 0; ;;
*) print_usage; exit 1; ;;
esac
done
shift $((OPTIND - 1))
#######################################
utils_dir="$(cd "$(dirname "$0")"; pwd)"
declare -r utils_dir
if echo "$PATH" | grep -v "$utils_dir" &> /dev/null; then
export PATH="$utils_dir:$PATH"
fi
declare i
if [[ $use_number == 'true' ]]; then
for i in $(seq "$1" -1 1); do
echo -n "$i " | color_print 102
sleep 1
done
color_print 102 '0'
else
for i in $(seq "$1" -1 1); do
color_print 102 '.'
sleep 1
done
echo ''
fi