The script below will break at first ssh command. Not erroring out, but breaking the while loop. Debugging the script with set -vx will indicate that the read -r line does not read anything else from the variable being iterated.
Once I comment out the ssh line, it will work happily and iterate over the entire loop.
Can you help unravel the mystery here?
Thanks!
Script:
#!/bin/bash
set -vx
file_list=$(cat <<EOT
aaa
bbbb
ccccc
dddddd
eeeeeee
EOT
)
while read -r line; do
echo ${line}
ssh 192.168.100.222 touch /tmp/${line}
done <<< "${file_list}"
Output with ssh line commented (set -vx was left out here)
aaa
bbbb
ccccc
dddddd
eeeeeee
Output with the ssh line enabled
aaa
ssh 192.168.100.222 echo "1"