Team, am trying to print all elements for array with some string in bash over for loop but its just print elements not the string along.
if [ "$FILTER" = "ALL" ]; then
vm_ip_all=$(./command_to_get_ips)
printf "got all IPs \\n %s" "$vm_ip_all"
else
echo "could not get all IPs"
fi
#for vm_ip in "${vm_ip_all[@]}"; do <<same result as below
for vm_ip in "${vm_ip_all}"; do
printf "\\n BEGIN FOR \\n"
echo "iterating for $vm_ip"
echo "END FOR"
done
Actual output:
got all IPs
10.0.1.6
10.0.1.10
BEGIN FOR
iterating for 10.0.1.6
10.0.1.10
Expected output:
got all IPs
10.0.1.6
10.0.1.10
BEGIN FOR
iterating for 10.0.1.6
iterating for 10.0.1.10
END FOR
vm_ip_all
10.0.1.6 10.0.1.10 ```