Associative arrays: error "declare: -A: invalid option"
Solution 1:
Make sure the version of bash being invoked as interpreter at the top of your shell script (#!/bin/bash
or whatever) is also version 4. If you're doing:
bash --version
and it's giving you v4, do a which bash
to check it's location.
Solution 2:
Here is a Workaround, if you want to use chars as array index with bash v3:
array=(
'hello::world.'
'nice::to meet you'
)
for index in "${array[@]}" ; do
KEY="${index%%::*}"
VALUE="${index##*::}"
echo "$KEY - $VALUE"
done
Output:
hello - world.
nice - to meet you