I am having the following bash file which I use as configuration:
# config
servers=(
[vagrant.host]=192.168.20.20
[vagrant.port]=22
[vagrant.user]=ubuntu
[vagrant.identity]=~/.ssh/id_rsa
[vagrant.cwd]=/home/ubuntu/website
)
and I load it from my main script using:
declare -A servers
. config
echo "${servers["vagrant.host"]}" # prints 192.168.20.20
If the code is not in a function it works great, but I don't need the config file always loaded and I put the loading code in a function. When I call the function like shown below I receive an error.
function loadConfig {
declare -A servers
. config
}
loadConfig
echo "${servers["vagrant.host"]}"
# vagrant.host: syntax error: invalid arithmetic operator (error token is ".host")
I have no idea what is causing the error and Google didn't help.