Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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"
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
add comment

1 Answer

up vote 9 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
1  
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
add comment

Your Answer

 
discard

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.