Remote for-loop over SSH

I have the adhering to in a manuscript

for server in ${servers[@]}; do
 echo ${server}
 ssh [email protected]${server} "for i in /tmp/foo* ; do echo ${i}; done"

Yet it does not function. Unusual point, I see $I quantity of return lines. So if I have 10 files, I see 10 empty lines.

2019-05-04 03:40:33
Source Share
Answers: 1

Your neighborhood shell interpretes the ${i} within double quotes (" ), so the command exercises to

ssh [email protected] "for i in /tmp/foo* ; do echo; done"

Merely make use of solitary quotes (' ) rather and also your trouble will certainly go away :

ssh [email protected]${server} 'for i in /tmp/foo* ; do echo $i; done'
2019-05-07 23:54:52