bug-bash
[Top][All Lists]
Advanced

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

Re: Some incorrect behaviour for BASH arrays


From: Victor Pasko
Subject: Re: Some incorrect behaviour for BASH arrays
Date: Thu, 31 Aug 2023 19:39:09 +0700

Thanks for prompt response. But see my comments below.

Well, instead of the following line

RESULT=''

done

declare -p RESULT

without initialization, because otherwise I got the following error "-bash:
declare: RESULT=: not found".

And after deleting/commenting the following fragment in badrev

#if [ $i -ge $QSTRING ] ; then
#echo "XXX-break i=$i result=$RESULT size=${#RESULT}"
#break
#fi

and correcting end echo-line to

echo " result=${RESULT[0]} size=${#RESULT[0]}"

i can see strange output for badrev:
declare -a RESULT=([0]="987654321" [1]="B" [2]="1" [3]="2" [4]="3" [5]="\\"
[6]="-" [7]="4" [8]="5" [9]="6" [10]="7" [11]="\\" [12]="-" [13]="8")
        result=9 size=1
Still incorrect output and size:( How to get correct output? ${RESULT[0]}
???

result=${RESULT[0]} size=${#RESULT[0]} ### does not work :(

BTW, in the presented link to the manual with  *6.7 Arrays*
there is no explanation for *declare -p *:(

Still unclear output for badsed

BAD variants of sed
        string=Bb12345678 QSTRING=10
declare -a RESULT=([0]="bB123\\-4567\\-8" [1]="8" [2]="7" [3]="6" [4]="5"
[5]="4" [6]="3" [7]="2" [8]="1" [9]="6" [10]="7" [11]="\\" [12]="-"
[13]="8")
DEBUG i-symbol=B
DEBUG i-symbol=b
DEBUG i-symbol=1
DEBUG i-symbol=2
DEBUG i-symbol=3
DEBUG i-symbol=4
DEBUG i-symbol=5
DEBUG i-symbol=6
DEBUG i-symbol=7
DEBUG i-symbol=8
        result=B size=1


On Thu, Aug 31, 2023 at 4:49 AM Lawrence Velázquez <vq@larryv.me> wrote:

> On Wed, Aug 30, 2023, at 2:12 PM, Victor Pasko wrote:
> > Attached please find bug.bash to reproduce incorrect BASH behaviour for
> > BASH arrays
> > and look at ways to run it
>
> Your tests are flawed.  The lines you use to inspect RESULT...
>
> > badsed() { # just array indexes are used for RESULT
> >   ...
> >   echo -n "   result=$RESULT size=${#RESULT}"
> >   echo " ${RESULT:0:$k}"
> > }
> >
> > ...
> >
> > badrev() {
> > ...
> > if [ $i -ge $QSTRING ] ; then
> > echo "XXX-break i=$i result=$RESULT size=${#RESULT}"
> > break # XXX
> > fi
> >   done
> >   echo "      result=$RESULT size=${#RESULT}"
> > }
>
> ...are actually only inspecting element 0 of RESULT.  As per the
> manual, "[r]eferencing an array variable without a subscript is
> equivalent to referencing with a subscript of 0" [*].
>
> Try using ''declare -p RESULT'' instead.
>
> [*] https://www.gnu.org/software/bash/manual/html_node/Arrays.html
>
> --
> vq
>


-- 

-- PSK


reply via email to

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