Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following in a script

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

But it doesn't work. Weird thing, I see $I amount of return lines. So if I have ten files, I see ten blank lines.

share|improve this question
look also at GNU Parallel's --sshlogin option. – Sebastian Jun 10 '11 at 8:48
up vote 11 down vote accepted

Your local shell interpretes the ${i} within double quotes ("), so the command works out to

ssh user@some.serv.er "for i in /tmp/foo* ; do echo; done"

Simply use single quotes (') instead and your problem will disappear:

ssh user@${server} 'for i in /tmp/foo* ; do echo $i; done'
share|improve this answer
Just to clarify your answer: ssh user@some.serv.er 'for i in /tmp/foo* ; do echo $i; done' Thanks! – Eldelshell Sep 1 '10 at 11:48
Thanks a lot :) i was searching to execute the multiple command with ssh option, this post helped me a lot – user17982 Apr 22 '12 at 18:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.