-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07_if_else.bash
More file actions
39 lines (34 loc) · 884 Bytes
/
07_if_else.bash
File metadata and controls
39 lines (34 loc) · 884 Bytes
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
#!/usr/bin/env bash
### Primary and combining expressions (https://github.com/denysdovhan/bash-handbook#primary-and-combining-expressions)
# [the difference between double and single square brackets in bash](http://serverfault.com/a/52050)
# if [ 1 -eq 2 ]; then
# echo "true"
# else
# echo "false"
# fi
# if [ `uname` == "Adam" ]; then
# echo "Do not eat apple!"
# elif [ `uname` == "Eva" ]; then
# echo "Do not take apple!"
# else
# echo "Eat apple! $(uname)"
# fi
### Challenge
if [[ $1 -ge 0 && $1 -lt 12 ]]; then
echo "Good morning!"
elif [[ $1 -ge 12 && $1 -lt 18 ]]; then
echo "Good afternoon!"
elif [[ $1 -ge 18 && $1 -le 24 ]]; then
echo "Good evening!"
else
echo "Error!"
fi
# Or
HOUR=$(date +%H)
if [[ $HOUR -lt 12 ]]; then
echo "Good morning!"
elif [[ $HOUR -ge 12 && $HOUR -lt 18 ]]; then
echo "Good afternoon!"
else
echo "Good evening!"
fi