1

I have a section of code that looks like:

while IFS= read -r line
do

(tab)...
(tab)...
(tab)ssh root@${ipaddress} <<-EOF
(tab)...
(tab)...
(tab)EOF

   echo $done with ${ipaddress}

done < file.dat

There are multiple lines within 'file.dat' that contain the ${ipaddress} variable, however, the above script only runs for the first line of data. If I take out the ssh / EOF section, it will properly loop through all of the lines within file.dat. What am I missing?

Miss_Orchid
  • 308
  • 1
  • 8
  • does it work if you remove the indent? `<<-` only works with a literal tab iirc – ti7 Aug 25 '23 at 00:52
  • 1
    I edited the initial post - when I literally hit 'tab' on the keyboard, it does not indent in the code section. – Miss_Orchid Aug 25 '23 at 00:55
  • 1
    Please make a [mre]. I bet there's actually some other command in the loop that's sopping up the rest of stdin, bypassing `read`. Or maybe SSH can do that, I can't remember off the top of my head. [It can certainly do that without a heredoc.](//unix.stackexchange.com/q/107800/117037). – wjandrea Aug 25 '23 at 00:59
  • see https://stackoverflow.com/questions/13800225/while-loop-stops-reading-after-the-first-line-in-bash – pynexj Aug 25 '23 at 01:05
  • @wjandrea as noted in the original post, when I have removed the ssh section, it reads the text file without issues for every line. – Miss_Orchid Aug 25 '23 at 13:06
  • 1
    following the marked duplicate, does it work with `ssh -n`? otherwise what's in the ssh section? tabs vs spaces is easily settled (ha, flamewar ensues) and this is likely not related .. that they're aware of the _potential_ issue is quite sufficient to check for themselves as [SO doesn't support literal tabs (which is most problematic for Makefiles)](https://meta.stackoverflow.com/questions/403016/) .. see also the more concise https://stackoverflow.com/questions/49804389/ssh-inside-ssh-heredoc – ti7 Aug 25 '23 at 19:08
  • @Miss_Orchid Yes, I saw that, but there are still too many variables to consider (at least for me not being an SSH expert). – wjandrea Aug 25 '23 at 19:12

0 Answers0