-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashUtilFunctions.sh
69 lines (59 loc) · 1.54 KB
/
bashUtilFunctions.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
set -euo pipefail
function check_write_request_output() {
output=$1
url=$2
if [ $(echo "$output" | wc -l) -ne 2 ]; then
exit 1
fi
first_line=$(echo "$output" | head -n 1)
second_line=$(echo "$output" | tail -n 1)
IFS=':' read -ra line <<<"$first_line"
rest_of_string="${line[1]}"
for j in "${line[@]:2}"; do
rest_of_string+=":$j"
done
rest_of_string="${rest_of_string:1}"
if [ "${line[0]}" != "Long URL" ] || [ "$rest_of_string" != "$url" ]; then
exit 1
fi
IFS=':' read -ra line <<<"$second_line"
rest_of_string="${line[1]}"
for j in "${line[@]:2}"; do
rest_of_string+=":$j"
done
rest_of_string="${rest_of_string:1}"
if [ "${line[0]}" != "Short URL" ]; then
exit 1
fi
echo "$rest_of_string"
}
function check_read_request_output() {
output=$1
url=$2
result_url=$3
# Check if output has two rows
if [ $(echo "$output" | wc -l) -ne 2 ]; then
exit 1
fi
first_line=$(echo "$output" | head -n 1)
second_line=$(echo "$output" | tail -n 1)
IFS=':' read -ra line <<<"$first_line"
rest_of_string="${line[1]}"
for j in "${line[@]:2}"; do
rest_of_string+=":$j"
done
rest_of_string="${rest_of_string:1}"
if [ "${line[0]}" != "URL" ] || [ "$rest_of_string" != "$url" ]; then
exit 1
fi
IFS=':' read -ra line <<<"$second_line"
rest_of_string="${line[1]}"
for j in "${line[@]:2}"; do
rest_of_string+=":$j"
done
rest_of_string="${rest_of_string:1}"
if [ "${line[0]}" != "Result URL" ] || [ "$rest_of_string" != "$result_url" ]; then
exit 1
fi
}