[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: is there a way to reverse list $@
From: |
Greg Wooledge |
Subject: |
Re: is there a way to reverse list $@ |
Date: |
Wed, 23 Oct 2024 19:14:39 -0400 |
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[@]}"