Server Fault is a question and answer site for system and network administrators. 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

So I have been running local scripts fine on a remote server:

ssh user@server "`cat`"

However, today I have a script that has both single and double quotes in it. Which causes the script to fail because the output of cat is wrapped in quotes. With out modifying the script itself, is there a better way to handle this?

I thought this may work:

ssh user@server $(<

But is does not seem to do anything...

share|improve this question
up vote 3 down vote accepted

With the following test script:

uname -n
a=(b c 'd e' f)
echo "${#a[@]}"
b=(1 "2 3" 4)
echo "${#b[@]}"

The output should be the remote host name followed by 4 and 3 when executed using:

ssh user@server "$(<scriptname)"

This shows that the quotes inside the script are being handled correctly. If the quotes weren't being handled correctly, the numbers output would be 5 and 4 due to word splitting. Note the quotes around the command substitution.

By the way, the first command you posted doesn't work. The single quotes prevent the backticks from being evaluated locally.

share|improve this answer
You are correct about the single quotes. I have updated the question to reflect this. – Michael Irey Jun 28 '13 at 17:12
I have awarded the correct answer to you, because it was closest to what I originally had. I was just missing the quotes. Also because you provided a testable script. – Michael Irey Jun 28 '13 at 19:28
cat | ssh user@server bash

or whatever shell you want to use instead of bash

share|improve this answer
Excellent! And simple. – Michael Irey Jun 28 '13 at 16:08

Assume that the script is in file What the heck is the problem with running:

 ssh -T <

This works for me!

share|improve this answer
That's not doing what the OP wants. – Dennis Williamson Jun 28 '13 at 16:57
Corrected......... – mdpc Jun 28 '13 at 17:01
What is the difference between < and $(< ? – Michael Irey Jun 28 '13 at 19:29
See the message from Dennis Williamson. I still go for simplicity, why involve more work for a program to do when a simpler construct can do the same and is far readable too. – mdpc Jun 28 '13 at 19:36
@MichaelIrey: The difference is that a message stating that a pseudo-terminal is not allocated because of the redirection. You can suppress the resulting message by adding the -T option to your ssh command. – Dennis Williamson Jun 28 '13 at 20:09

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.