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 the following bash which works

export READ=$(cat /opt/TOKEN.txt);echo "initial_token: $READ" >> cassandra.yaml

I need to escape this so it runs over ssh properly so I tried the following

ssh host 'export READ=\$(cat /opt/TOKEN.txt);echo \"initial_token: \$READ\" >> cassandra.yaml'

yields error

bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `export READ=\$(cat /opt/TOKEN.txt);echo \"initial_token: \$READ\" >> cassandra.yaml'

as well as

ssh host 'export READ=\$\(cat /opt/TOKEN.txt\);echo \"initial_token: \$READ\" >> cassandra.yaml'

yields error

bash: line 0: export: `/opt/TOKEN.txt)': not a valid identifier

Anyone know how to escape this? thanks, Dean

share|improve this question
up vote 3 down vote accepted

You are escaping too much – bash already does no interpretation of single-quoted strings:

ssh host 'READ=$(< /opt/TOKEN.txt); echo "initial_token: $READ" >> cassandra.yaml'
share|improve this answer

ah man, this is waaaaaayyyyy cool. I just found this so I don't need to worry about escaping ANYHTHING...

ssh user@serverB <<\EOF
your sql query....
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.