bash - loss of data in 2nd insert into associative array -


in code below second insert associative array 'originator', makes first insert lost. check 1st insert succesfull, when put second associative item 'originators', first item empty, in other words, outputs , empty string. have no idea going on.

declare -a originators      while read -r line             if [ "$count" -ge "2" ];                      inner_count=0             #parse each line             if [ "$debug" = "1" ] ;  printf "%s\n" "$line" ; fi              word in $line                               if [ "$inner_count" = "1" ]; tmp1="$word" ; fi                 if [ "$inner_count" = "5" ]; tmp1="$tmp1"" ---- ""$word" ;fi                  inner_count=$((inner_count + 1))              done                     originators=( ["$count"]="$tmp1" )             echo "$count  ${originators["$count"]}"          fi     count=$((count + 1))     done < <(batctl tg) 

you're indeed overwriting array in line:

originators=( ["$count"]="$tmp1" ) 

it should changed to:

originators+=( ["$count"]="$tmp1" ) 

this += operator append new values array.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -