-
Notifications
You must be signed in to change notification settings - Fork 0
/
ini_reader.sh
47 lines (39 loc) · 853 Bytes
/
ini_reader.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
function read_ini() {
if [ "$#" -ne 2 ]; then
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!"
echo -e "usage: readIni filePath itemKey"
echo -e "!!!!!!!!!!!!!!!!!!!!!!!!"
return 255
fi
filename="$1"
checkKey="$2"
itemFound=false
while read line
do
if [ "${line:0:1}" = "#" ]; then
# skip comments
continue
fi
if [ -z "${line}" ]; then
# skip empty lines
continue
fi
keyValue=(${line//=/ })
if [ "${#keyValue[*]}" -ne 2 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "invalid ini line inside file: ${line}"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 255
fi
if [ "${keyValue[0]}" != "${checkKey}" ]; then
continue
fi
echo "${keyValue[1]}"
itemFound=true
break
done < $filename
if [ "${itemFound}" != true ]; then
echo "Ini item ${itemKey} not found"
exit 255
fi
}