0
    303   for count in "${nodeof[@]}"; do
    304       lines=`GetNodeMemory $count`
    305       printf %s "$lines" | while IFS= read -r line; do \
    306       {
    307         key=`echo $line | awk -F':' '{print $1}' | cut -d' ' -f3`
    308         [[ -z ${key} && ${key} ]] && continue
    309         for chk in "${MemVar[@]}"; do
    310             [[ "${key}" == "${chk#*:}" ]] && break
    311         done
    312         #echo "ke:${chk#*:} - ind:${chk%%:*}"
    313         NodeMem[$count,${chk%%:*}]=`echo $line \
    314               | /bin/grep -i "${key}" | awk -F':' '{print $2}' \
    315               | cut -d' ' -f2`
    316        #echo "${chk#*:} ${NodeMem[$count,${chk%%:*}]}"
    317        chk=""
    318       } done
    319   done
    320 
    321   for count in "${nodeof[@]}"; do
    322       for chk in "${MemVar[@]}"; do
    323            echo "${NodeMem[${count},${chk%%:*}]}"
    324       done
    325   done

Here NodeMem is a two dimensional array, and if I print using line#316, array values print fine. But, if print using line#323, output is just empty lines. What is happening here? Thanks for the help.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • First, you need to start learning how to use comments. – SaintHax May 09 '16 at 17:36
  • 1
    Thanks @user000001, I overlooked pipeline, replaced pipeline mechanism with a temp file write/read. Unfortunately, current bash in our OS is 4.0, I can not use last pipe option. Problem solved. – Userdijkstra May 09 '16 at 17:59

1 Answers1

1

Bash doesn't support multidimensional arrays. When you are assigning foo,bar it's evaluting that to index 0. With the syntax you are using, array[1,5] is the same as array[5]. Also array[2,5] is the same as array[5].

See this previous post on how to fake a multidimensinal array Bash two dimensional arrays

Community
  • 1
  • 1
SaintHax
  • 1,875
  • 11
  • 16