help-bash
[Top][All Lists]
Advanced

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

Re: Use of $@


From: alex xmb ratchev
Subject: Re: Use of $@
Date: Thu, 23 Feb 2023 14:30:00 +0100

On Thu, Feb 23, 2023, 1:30 PM Christof Warlich <cwarlich@gmx.de> wrote:

> Am 21.02.23 um 23:48 schrieb Chet Ramey:
> > "${!@}" is not a useful expansion. It ends up being indirect expansion,
> > since it's not defined to do anything else, and "$@" in a context where
> > word splitting doesn't take place rarely expands to a usable variable
> > name.
> Yes, I got that :-).
> > It is not equivalent to ${!1} ${!2} ... .
>
> I would have assumes it to iterate over the indices of "$@", in the same
> way as for the array a=(hi ho), ${!a[@]} iterates over the indices of
> "${a[@]}":
>
> $ a=(hi ho)
> $ for i in "${!a[@]}"; do echo $i; done
> 0
> 1
>
> ... but (to me, unexpectedly) the following does not work:
>
> $ a=(hi ho)
> $ f() for i in "${!@}"; do echo $i; done
> $ f "${a[@]}"
> bash: hi ho: invalid variable name
>

maybe the elems are just clear , from 1 if existing , upwards ..

f() { declare -a "e=( {1..$#} )" ; for i in ${e[@]} ; do echo $i ; done ; }
; f a b c                                       1
2                                                             3

( shitpaste - but u see 1 .. 3 )

Wouldn' it make sense to make "${!a[@}" and "${!@}" behave similar in
> some future version of bash?
>
>
>
>


reply via email to

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