Hello!

Am Tue, 20 Oct 2020 00:58:36 -0700 schrieb L A Walsh <b...@tlinx.org>:
> There's got to be an easier way to do this, but not remembering or finding
> it:
> 
> First tried the obvious:
> declare -a ar1=([0]="1" [1]="2" [2]="3" [3]="44")
> an=ar1
> echo ${#!an[@]}
> -bash: ${#!an[@]}: bad substitution
> 
> This works but feels kludgy
> 
> an=ar1
> eval echo \${#$an[@]}
> 4

I'm not quite sure what exactly you intend, but if you use

  declare -n an=ar1

instead of an=ar1, then

  echo ${#an} ${an[3]}

will work as I expect.

Best regards

Martin

Reply via email to