#!/bin/bash getConfig() { while read key value do case $key in '#'*) #comment ;; '') #empty line ;; '[general]') context=General ;; '[source]') context=Source ;; \[*\]) context=Destination destination="${key#[}" destination="${destination%]}" destinations+=("${destination%]}") ;; *) getConfig$context ;; esac done < "$cffile" }