Skip to main content
Became Hot Network Question
Became Hot Network Question
Formatting and rephrase title
Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Problem with Problems iterating over several Bash arrays in Bashone loop

Source Link
dg72
  • 87
  • 1
  • 4

Problem with arrays in Bash

I have problems with some arrays in bash.

A=( "127.0.0.1" "localhost" "aaa nnn cvcc" )
B=( "8.8.8.8"  "dns" "bbb tttt rrrr")

for n in ${A} ${B} ;  do

 if ping -c3 ${n[0]};then
  echo "${n[1]}"
    for share in ${n[2]};do
      echo $share
    done
 fi
done

I'd like to print the second and third element of the array but the for loop stop at the ping. This way it is working.

if ping -c3 ${A[0]};then
 echo "${A[1]}"
 for share in ${A[2]};do
  echo $share
 done
fi

I'm sure must be a very silly thing but it is driving me mad... Some ideas? Many thanks in advance