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