-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversionhighest.sh
executable file
·52 lines (39 loc) · 1.06 KB
/
versionhighest.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
51
52
#!/bin/bash
# CLI tool for returning the highest version
# or determining if a given version is the highest.
#
# Requirements:
# - bash 4
# - cat
# - tail
source "$(dirname "${BASH_SOURCE[0]}")"/comparator/compare.sh
source "$(dirname "${BASH_SOURCE[0]}")"/sorter/sort.sh
if [ -z "$1" ]; then
cat <<EOT
Usage: versionhighest.sh <versions> [version]
<versions> newline-delimited versions to sort
[version] optional version to compare
Output:
If only a version list is specified, the highest version of that list is output.
If a specific version is specified as well, YES is output if it is the same as
or higher than the highest version in the list, NO otherwise.
EOT
exit 64;
fi;
HIGHEST_VERSION=$(andaris_version_sort "$1" ASC | tail -n 1);
RESULTCODE=$?;
if [ -z "$2" ]; then
echo "$HIGHEST_VERSION";
exit $RESULTCODE;
fi;
RESULT=$(andaris_version_compare "$HIGHEST_VERSION" "$2");
RESULTCODE=$?;
if [ $RESULTCODE -ne 0 ]; then
exit $RESULTCODE;
fi;
if [ "$RESULT" == "B" ] || [ "$RESULT" == "0" ]; then
echo "YES";
else
echo "NO";
fi;
exit 0;