[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: is there a way to reverse list $@
From: |
#!microsuxx |
Subject: |
Re: is there a way to reverse list $@ |
Date: |
Thu, 24 Oct 2024 02:00:20 +0200 |
yea , err :)) i done awk , .. the data bash processed anyway came from awk
great greets ..
On Thu, Oct 24, 2024, 01:15 Greg Wooledge <greg@wooledge.org> wrote:
> On Thu, Oct 24, 2024 at 00:54:39 +0200, #!microsuxx wrote:
> > i tried ${@:$#:-4} where 5 args and the last four in reverse order are
> > wanted
> > if not i do in awk
>
> There is no parameter expansion syntax that expands in reverse.
> If you want to iterate over the arguments in reverse order, use a loop:
>
> for ((i=$#; i>=1; --i)); do
> arg=${!i}
> printf 'Argument %s is %s\n' "$i" "$arg"
> done
>
> If you want the reversed arguments stored in an array, you'll have to
> build such an array yourself.
>
> rev=()
> for ((i=$#; i>=1; --i)); do
> rev+=( "${!i}" )
> done
> my_list_processor "${rev[@]}"
>
>