How to print index in a 'for-loop' being executed in remote host through SSH?

Posted by YShin on Super User See other posts from Super User or by YShin
Published on 2014-08-20T21:10:04Z Indexed on 2014/08/20 22:23 UTC
Read the original article Hit count: 211

Filed under:
|
|

I want to ssh into a remote host, and then execute a for loop that goes through sequence of numbers to control number of different nodes.

ssh user@host /bin/bash << EOF
for i in {1..10}
do
echo $i
done
EOF

If I do this, the output is just 10 blank lines, instead of printing out numbers from 1 through 10.

If I execute same code on my local machine, I get the desired output which is ten lines each line printing from 1 through 10.

How would one achieve the intended functionality, that is accessing the index in a for loop that is being executed in SSH?

© Super User or respective owner

Related posts about bash

Related posts about ssh