1

I am trying to create an associative array in bash. I'm not sure if it's created because when I try to print it, nothing is displayed.

# create hash table of directories

START=0
END=39

# directory hash table
declare -A directories;

# directory name
dir_name="event-test-"

echo $dir_name

for i in {$START..$END}; do
        directories[$dir_name$i]=1;
        echo ${directories[@]};
done

The output I am getting when I source the .sh file is:

event-test-
1

Not sure if I am missing something when I try to create my associative array

Liondancer
  • 15,721
  • 51
  • 149
  • 255

1 Answers1

1

It's not possible to use variables in bash's Brace Expansion. Replace

for i in {$START..$END};

by

for ((i=$START;i<=$END;i++));
Cyrus
  • 84,225
  • 14
  • 89
  • 153