I am running a script inside a server to get a list of services and fetch corresponding logs of each service, below is my command
ssh root@xxx.xxx.xxx.xxx << 'EOF'
service_list=$(docker ps -a | grep services | awk '{print $1}')
echo $service_list
EOF
output is
service1 service2 service3
I want to cut this output or store them in an array so i can execute
docker logs $service_list[0]
and so on
I tried to store the output to an array
ssh root@xxx.xxx.xxx.xxx << 'EOF'
service_list=$(docker ps -a | grep services | awk '{print $1}')
echo $service_list
echo "print first value in array"
echo $service_list[0]
echo "print second value in array"
echo $service_list[1]
echo "print third value in array"
echo $service_list[2]
EOF
my output
service1 service2 service3
print first value in array
service1 service2 service3
print second value in array
print third value in array
a blank line is printed for second and third value in the array,for first value of array the complete service list is printed.
I am expecting an output like this while printing values in array
service1
service2
service3
any leads would be helpful