help-bash
[Top][All Lists]
Advanced

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

Re: Is the number of elements in an array tracked internally?


From: Zachary Santer
Subject: Re: Is the number of elements in an array tracked internally?
Date: Sun, 1 Jun 2025 15:24:03 -0400

On Sat, Apr 26, 2025 at 9:49 PM Zachary Santer <zsanter@gmail.com> wrote:
>
> On Sat, Apr 26, 2025 at 12:08 PM Greg Wooledge <greg@wooledge.org> wrote:
> >
> > f1() {
> >     local arg1 arg2 arg3
> >
> >     # The first 3 args are special, so we save them.
> >     arg1=$1 arg2=$2 arg3=$3
> >     shift 3
> >
> >     # All remaining args should appear in sets of 3.  Process each set.
> >     while (($#)); do
> >         f2 "$arg1" "$arg2" "$arg3" "$1" "$2 "$3"
> >         shift 3
> >     done
> > }
> >
> > Does that look right?
>
> There's a lot of other stuff going on in that while loop, so f1 ()
> isn't just passing sets of its arguments to f2 () on each loop
> iteration. What you're saying to do with shift would definitely work,
> though. If nothing else, the style of commenting I've started using
> really benefits from assigning all the function's input parameters to
> variables in one place.

I ultimately did change my while loop to assign to variables from the
function's input parameters and use shift like this. Thanks for the
suggestion.



reply via email to

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