bug-bash
[Top][All Lists]
Advanced

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

Re: find len of array w/name in another var...(bash 4.4.12)


From: Martin Schulte
Subject: Re: find len of array w/name in another var...(bash 4.4.12)
Date: Tue, 20 Oct 2020 10:20:59 +0200

Hello!

Am Tue, 20 Oct 2020 00:58:36 -0700 schrieb L A Walsh <bash@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

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