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: Lawrence Velázquez
Subject: Re: Some incorrect behaviour for BASH arrays
Date: Wed, 30 Aug 2023 17:48:50 -0400
User-agent: Cyrus-JMAP/3.9.0-alpha0-701-g9b2f44d3ee-fm-20230823.001-g9b2f44d3

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



reply via email to

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