This approach is not restricted to >= 5.0, which will probably be a huge deal to some people looking to write more portably. It works in >= 3.1. Tested in all full releases of BASH from 3.0 to 5.1.8.
reverse_array() {
local Buffer=("$@")
for (( Index = $# - 1; Index >= 0; Index-- )); {
printf '%s\n' "${Buffer[Index]}"
}
}
The only reason it didn't work in BASH 3.0 and 3.0.16 was because of the local builtin — perhaps an old bug or limitation later addressed.
https://github.com/dylanaraps/pure-bash-bible#reverse-an-array
This approach is not restricted to >= 5.0, which will probably be a huge deal to some people looking to write more portably. It works in >= 3.1. Tested in all full releases of BASH from 3.0 to 5.1.8.
The only reason it didn't work in BASH 3.0 and 3.0.16 was because of the
local
builtin — perhaps an old bug or limitation later addressed.