1

I have the following variable IP_LIST

The command echo $IP_LIST gives the result

"10.36.107.121" "10.45.167.243" "10.12.154.43"`

I am trying to store the result into an array using the command

myarray=(`echo $IP_LIST | tr ' ' ' '`)

But on the command echo $myarray I am getting the result

"10.36.107.121"

Whats the possible error

3
  • 1
    What are you trying to do with that tr? Commented Jun 11, 2021 at 11:55
  • golinuxcloud.com/bash-split-string-into-array-linux. This tells me that tr is used to split strings Commented Jun 11, 2021 at 12:02
  • 2
    Whats the possible error There's no error and everything is working as it should. Did you expect something different to be printed out? ` This tells me that tr is used to split strings –` No, that is not what is says. On that site tr is used to replace , with a space. There's no point in changing space into a space... tr ' ' ' ' is useless. Just myarray=($IP_LIST) Commented Jun 11, 2021 at 12:07

1 Answer 1

2

echo "${myarray[@]}" will print out the full array, instead of only the first element. You build the array correctly, but the echo statement was wrong.

cfr how to use arrays and specific indexes here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.