36 lines
800 B
Bash

#!/bin/bash
getConfig() {
# Read the config file line by line; 'key' gets the first word, 'value'
# the rest
while read key value
do
case $key in
'#'*)
#comment - skip comment lines
;;
'')
#empty line - skip blank lines
;;
'[general]')
# Switch parsing context to the [general] section
context=General
;;
'[source]')
# Switch parsing context to the [source] section
context=Source
;;
\[*\])
# Any other [section] header is a destination name
context=Destination
destination="${key#[}"
destination="${destination%]}"
destinations+=("${destination%]}") # Append to list of destinations
;;
*)
# Dispatch key=value to the handler for the current section context
getConfig$context
;;
esac
done < "$cffile"
}