Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Much More Compatible reverse_array() #119

Open
ghost opened this issue Dec 24, 2021 · 0 comments
Open

Much More Compatible reverse_array() #119

ghost opened this issue Dec 24, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 24, 2021

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.

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants