I have this array:
declare -A modeAndAction
modeAndAction[category]=create
modeAndAction[attribute]=create
modeAndAction[customers]=create
modeAndAction[newsletter]=create
modeAndAction[vouchers]=create
modeAndAction[products]=create
modeAndAction[orders]=create
Which outputs this:
Starting import of mode : attribute
With action: create
Starting import of mode : category
With action: create
Starting import of mode : newsletter
With action: create
Starting import of mode : vouchers
With action: create
Starting import of mode : orders
With action: create
Starting import of mode : customers
With action: create
Starting import of mode : products
With action: create
But I expect this output:
Starting import of mode : category
With action: create
Starting import of mode : attribute
With action: create
Starting import of mode : customer
With action: create
Starting import of mode : newsletter
With action: create
Starting import of mode : vouchers
With action: create
Starting import of mode : products
With action: create
Starting import of mode : orders
With action: create
So everything moved in the output, ignoring its declartion, but I dont understand why. I want the modes (+ its action) to be called exactly in the order I have the array declared in.
Bash Version:
GNU bash, version 4.2.51(1)-release (x86_64-pc-linux-gnu)
//Edit I found out that if I have this array
modeAndAction[AAAAAAAAA]=create;
modeAndAction[B]=create;
modeAndAction[C]=create;
modeAndAction[D]=create;
I get this output:
Starting import of mode : B
With action: create
Starting import of mode : C
With action: create
Starting import of mode : D
With action: create
Starting import of mode : AAAAAAAAA
With action: create
So it auto-sorts it by key lenght.
//Edit2 Code for responsible for the output
for i in "${!modeAndAction[@]}"
do
echo "Starting import of mode : $i"
echo "With action: ${modeAndAction[$i]}"
done