bash: bad array subscript

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

When iterating over an array, you may encounter the error:
myscript.sh: line N: bad array subscript

Check that you are not trying to access a value in the array using a negative index.
Also check that when trying to print something like ${my_map[$KEY]}, $KEY does evaluate to something valid, that it is not an empty string. ${my_map[]} would produce the error above.