bug-bash
[Top][All Lists]
Advanced

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

Re: Fwd: Some incorrect behaviour for BASH arrays


From: Victor Pasko
Subject: Re: Fwd: Some incorrect behaviour for BASH arrays
Date: Sun, 3 Sep 2023 00:50:44 +0700

Kerin ,

Thanks for this suggestion but mostly the number of parts for some string
would be equal to the size of the input string.
So, it means that for every string it needs to associate special bash-array
with the same size and in order to get the result do join all
bash-array-elements.

On Fri, Sep 1, 2023 at 3:35 PM Kerin Millar <kfm@plushkava.net> wrote:

> On Fri, 1 Sep 2023 14:44:49 +0700
> Victor Pasko <victor.pasko@gmail.com> wrote:
>
> > Just forward my response to all who was involved in discussion of my
> request
> >
> > ---------- Forwarded message ---------
> > From: Victor Pasko <victor.pasko@gmail.com>
> > Date: Fri, Sep 1, 2023 at 2:23 PM
> > Subject: Re: Some incorrect behaviour for BASH arrays
> > To: Kerin Millar <kfm@plushkava.net>
> >
> >
> > Thanks for the detailed explanations of *declare *.
> >
> > As to the idea behind of my request:
> > 1) I need local variable RESULT as empty string (not array)
> > 2) this RESULT should collect symbols taken from other strings using
> > ${STRING:i:1} for one symbol or ${STRING:i:k} for k-symbols
> > So, the main question is: how to save such sub-strings in RESULT at
> needed
> > j-place?
> > With another words - I need RESULT as C-char-array to use it something
> like
> > this
> >
> > RESULT[j]="${STRING:i:1}"
>
> You would have to reassemble RESULT from the appropriate substrings.
>
> $ RESULT=cat; STRING=moo; i=1 j=1;
> RESULT=${RESULT:0:j}${STRING:i:1}${RESULT:j+1}; declare -p RESULT
> declare -- RESULT="cot"
>
> Alternatively, use an array then finish by joining its elements, using the
> [*] subscript.
>
> f() {
>     local RESULT=(c a t)
>     local STRING=moo
>     local IFS=
>     local i=1 j=1
>     RESULT[j]=${STRING:i:1}
>     printf '%s\n' "${RESULT[*]}" # joins elements by first char of IFS
> (empty string)
> }
>
> --
> Kerin Millar
>


-- 

-- PSK


reply via email to

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