A loop is generally slow in bash, so I chose to use readarray to create a reversed array...
declare -a aReversed
readarray -d '' -t aReversed < <(printf '%s\0' "$@" | tac -s $'\0')
# aReversed now contains an array of arguments in reverse order
printf 'ARG %s\n' "${aReversed[@]}"
# or
for zArg in "${aReversed[@]}"; do
printf 'ARG %s\n' "$zArg"
done
This handles newlines in arguments because...
readarray -d '' # tells readarray to split on null terminator (the space is needed)
readarray -t # tells readarray to exclude the terminator from the array values.
- printf '\0' # tells printf to output a null byte.
tac -s '$\0' # tells tac that the file is null byte terminated.