Le Sun, May 24, 2026 at 07:37:11PM -0400, Zachary Santer a écrit :
> This would definitely see a fair bit of use. If you want to iterate
> through array elements in reverse order, currently you're stuck using
> an arithmetic for loop to iterate through their indices in reverse
> order. Something I've done myself.
Currently, I use extdebug in order to avoid loop for this:
revArray() {
function _funcRevArray() {
local -n _fRevVar=$1
shift
_fRevVar=("${BASH_ARGV[@]::$#}")
}
local -n _revVarCnt=$1
local _revVarName=$1
shift
shopt -s extdebug
_funcRevArray "$_revVarName" "${_revVarCnt[@]}"
shopt -u extdebug
}
myarry=( a\ a b\ b c\ c d\ d 4\ 4 5\ 5 6\ 6 )
revArray myarry
declare -p myarry
declare -a myarry=([0]="6 6" [1]="5 5" [2]="4 4" [3]="d d" [4]="c c" [5]="b
b" [6]="a a")
(See: https://mywiki.wooledge.org/BashFAQ/118)
--
Félix Hauri - <[email protected]> - http://www.f-hauri.ch