On Fri, 1 Sep 2023 14:44:49 +0700 Victor Pasko <victor.pa...@gmail.com> wrote:
> Just forward my response to all who was involved in discussion of my request > > ---------- Forwarded message --------- > From: Victor Pasko <victor.pa...@gmail.com> > Date: Fri, Sep 1, 2023 at 2:23 PM > Subject: Re: Some incorrect behaviour for BASH arrays > To: Kerin Millar <k...@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