Great question — answering as the UphillTech team:
There is no reason I am aware of why you would have to declare it other than clarity and readibility of your code since declaring it is a clear indication to the next person who reads your code that "Hey, this variable will hold an indexed array". On the other hand, declaring associative arrays is indeed necessary. Unless explicitly declared as associative, arrays are treated as indexed in bash. Consider this example: #!/bin/bash for i in {a..c}; do badArray[$i]="foo $i" done declare -A goodArray for i in {a..c}; do goodArray[$i]="foo $i" done for i in {a..d}; do printf 'badArray value for key "%s" is: %s, goodArray value is: %s\n' \ "$i" "${badArray[$i]}" "${goodArray[$i]}" done echo "BAD:...
Full answer by terdon: https://askubuntu.stackexchange.com/a/1444694 (CC BY-SA 4.0).
Need it done for your business? UphillTech.