Escape characters in systemd ExecStart fail

Solution 1:

The easy way to debug this is to add option -v to the sh -c in order to see what systemd is actually passing it. If we do this we can see we are getting (reduced for readability):

curl ... | sed "s/... main-class="hudson...">.../\1/" >>...

The syntax error is that the double-quoted command given to sed has inside it " instead of \". This is because systemd replaces \" by " indiscriminately in the ExecStart string.

You need to pass a backslash to sh by using \\ (which systemd will reduce to \), then the double-quote:

ExecStart=/bin/sh -cv 'curl... | sed "s/...main-class=\\"hudson...