#!/bin/bash AR=([3]='foo' [5]='bar' [25]='baz' [7]='bat') for i in "${!AR[@]}"; do printf '${AR[%s]}=%s ' "$i" "${AR[i]}" done