Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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....
.....
.....
EOF
share|improve this answer

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.