Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 a command that I want to run on machine B from machine A. If I run the command on machine B locally, it works fine.

Here is the command:

for n in `find /data1/ -name 'ini*.ext'` ; do  echo cp $n "`dirname $n `/` basename $n 
.ext`"; done

From machine A, I issue this command

ssh user@machineB  for n in `find /data1/ -name 'ini*jsem'` ; do  echo cp $n "`dirname $n `/` basename $n .jsem`"; done

But I get error syntax error near unexpected token do

What is wrong? I think it has something to do with double quotes, single quotes, semi colon because executing command ssh user@machineB ls works fine. So not issue of authentication or something else.


share|improve this question
Answer is to use a script and then issue ssh user@machineB 'bash -s ' < script Hope it helps somebody. – Ian McGrath Mar 28 '12 at 9:06

The problem is that your local shell is interpreting part of the command. You need to quote the entire command so that the remote shell executes it.

ssh user@machineB 'for n in `find /data1/ -name "ini*jsem"` ; do  echo cp $n "`dirname $n `/` basename $n .jsem`"; done'
share|improve this answer

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.