-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.sh
executable file
·72 lines (59 loc) · 1.24 KB
/
function.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
70
71
72
#!/bin/bash
_get_config_value() {
case $2 in
*"."*)
dotprocess $1 $2;;
*)
process $1 $2;;
esac
}
dotprocess()
{
extract=false
first="$(cut -d'.' -f1 <<<"$2")"
second="$(cut -d'.' -f2 <<<"$2")"
res=$(process $1 $first)
export IFS=" "
for word in $res; do
if $extract; then
echo $word
break
fi
if [[ "$word" == $second* ]]; then
extract=true
fi
done
}
process()
{
count_lines="0"
IFS=''
cat $1 | while read line; do
count_lines=$(($count_lines+1))
if [[ $line == $2* ]] && [[ $line != [[:blank:]]* ]]; then
IFS=": " read -ra ADDR <<< $line
if test -z ${ADDR[1]}; then
retval=$(iteration $count_lines $1)
echo $retval
else
echo ${ADDR[1]}
fi
break
fi
done
}
iteration()
{
iof=$(($1+1))
number_of_lines=$(cat $2 | wc -l)
for (( i=$iof; i<=$number_of_lines; i++))
do
line=$(sed "${i}q;d" $2)
if [[ $line != [[:blank:]]* ]]; then
break
else
echo $line
fi
done
}
$*