0

I have the command here

doctl compute ssh testdroplet --ssh-command 'echo -e "import http.server\nimport socketserver\nfrom http import HTTPStatus\n\nclass Handler(http.server.SimpleHTTPRequestHandler):\n    def do_GET(self):\n        self.send_response(HTTPStatus.OK)\n        self.end_headers()\n        self.wfile.write(b'Hello world')\n\nhttpd = socketserver.TCPServer(('', 8000), Handler)\nhttpd.serve_forever()" >> web/server.py'

which I need to write single quotes into a file. I changed the format to use single quotes outside echo because when I used double quotes the single quotes were not written to file (everything except the single quotes was written to file).

Now instead of a working command I get error

deploy_server % ./deploy_droplet.sh          
root@142.93.555.190's password: 
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
Error: exit status 1

How can I successfully write to file but also write in these single quotes? Thank you

codyc4321
  • 410
  • Look into ESCAPEing those quotes. This is a special char that tells the shell to ignore what you are passing. – Señor CMasMas Feb 26 '21 at 04:18
  • Note that you have four "layers" of quoting and/or escaping here: quotes/escapes that'll be applied (and removed) by the local shell, quotes/escapes that'll be applied (and removed) by the remote shell, escapes that'll be applied (and removed) by echo -e, and finally the quotes you want written into the remote file. It might be simpler to base64-encode what you want to put in the file instead of trying to thread your way through that many layers. – Gordon Davisson Feb 26 '21 at 08:22

0 Answers0