blob: ef21073c0c0b045af659a59f0dc7554617a189e5 (
plain)
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
|
# Integration: parse an INI file into shell variables, then use them.
cat >app.ini <<'INI'
; comment
[server]
host = example.org
port=8080
name = "My Server"
[paths]
root = /srv/www
logs = ${root}/logs
INI
section=
while IFS= read -r line || [ -n "$line" ]; do
line=${line%%;*}
case $line in
*[![:space:]]*) ;;
*) continue ;;
esac
case $line in
\[*\])
section=${line#\[}
section=${section%\]}
;;
*=*)
key=${line%%=*}
val=${line#*=}
key=$(echo $key)
val=$(echo $val)
val=${val#\"}
val=${val%\"}
eval "cfg_${section}_$key=\$val"
echo "set cfg_${section}_$key"
;;
esac
done <app.ini
echo "url: http://$cfg_server_host:$cfg_server_port/"
echo "name: $cfg_server_name"
echo "logs: $cfg_paths_logs"
[ "$cfg_server_port" -gt 1024 ] && echo "unprivileged port"
set | grep -c '^cfg_'
|