-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment_later
44 lines (39 loc) · 1 KB
/
comment_later
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
#COMPARE VARIABLE WITH A LIST IN AN IF
[[ ! $COLOR =~ BLUE|RED|GREEN ]] && {
echo "Incorrect options provided"
exit 1
}
#GETOPS
#!/bin/bash
while getopts "brgc:" OPTION; do
case $OPTION in
b)
COLOR=BLUE
;;
r)
COLOR=RED
;;
g)
COLOR=GREEN
;;
c)
COLOR=$OPTARG
[[ ! $COLOR =~ BLUE|RED|GREEN ]] && {
echo "Incorrect options provided"
exit 1
}
;;
*)
echo "Incorrect options provided"
exit 1
;;
esac
done
echo "Color is $COLOR"
exit 0;
#################################3
compare versions
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }
function version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; }
function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; }