bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add @R parameter transform to reverse expansion order


From: Félix Hauri
Subject: Re: [PATCH] Add @R parameter transform to reverse expansion order
Date: Thu, 28 May 2026 14:23:53 +0200

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  -  <felix@f-hauri.ch>  -  http://www.f-hauri.ch



reply via email to

[Prev in Thread] Current Thread [Next in Thread]