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: Greg Wooledge
Subject: Re: find len of array w/name in another var...(bash 4.4.12)
Date: Wed, 21 Oct 2020 07:59:36 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Tue, Oct 20, 2020 at 04:57:36PM -0700, L A Walsh wrote:
> 
> 
> On 2020/10/20 01:29, Andreas Kusalananda Kähäri wrote:
> > 
> > In bash 4.3+, I would manke your "ar" variable a name reference variable
> > instead:
> > 
> > $ ar1=(1 2 3 44)
> > $ declare -n ar=ar1
> > $ echo "${#ar[@]}"
> > 4
> > 
> Ya, I was trying to use the 'byname' feature for older/wider support...sigh

Well, your Subject: says bash 4.4.12.  If you're really targeting
bash 4.4, you should be able to use namerefs, such as they are.

If you can't use namerefs (because you're targeting something other
than what you said in the Subject:), then your next step would probably
be eval.

Overall, though, it sounds like you're writing something that's simply
too complicated for bash to do well.  Consider using another language,
or simplifying your data structures to eliminate this indirection.

If the X in your X-Y problem is "I'm trying to write a reusable function
that takes an array passed by name", then I refer you to
<https://mywiki.wooledge.org/BashWeaknesses>.



reply via email to

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