title: Getting unterminated 's' command with sed (bash)
body: <p>My final goal is to get a bunch of text above the COMMIT line in /etc/ufw/before.rules. I am trying to replace the COMMIT with something like this:
  <code>TEXT I WANT\nCOMMIT</code></p>
  
  <p>I see this as an easy sed command: <code>echo COMMIT | sed "s@COMMIT@${morerules}@g"</code></p>
  
  <p>I have set the variable <code>morerules</code> to a string like this:</p>
  
  <pre><code>morerules="""
  ### Start HTTP ###
  # Enter rule
  -A ufw-before-input -p tcp --dport 80 -j ufw-http
  -A ufw-before-input -p tcp --dport 443 -j ufw-http
  # Limit connections per Class C
  -A ufw-http -p tcp --syn -m connlimit --connlimit-above 50 --connlimit-mask 24 -j ufw-http-logdrop
  # Limit connections per IP
  -A ufw-http -m state --state NEW -m recent --name conn_per_ip --set
  -A ufw-http -m state --state NEW -m recent --name conn_per_ip --update --seconds 10 --hitcount 20 -j ufw-http-logdrop
  # Limit packets per IP
  -A ufw-http -m recent --name pack_per_ip --set
  -A ufw-http -m recent --name pack_per_ip --update --seconds 1 --hitcount 20 -j ufw-http-logdrop
  # Finally accept
  -A ufw-http -j ACCEPT
  # Log
  -A ufw-http-logdrop -m limit --limit 3/min --limit-burst 10 -j LOG --log-prefix \"[UFW HTTP DROP]\"
  -A ufw-http-logdrop -j DROP
  ### End HTTP ##
  """
  </code></pre>
  
  <p>As you can see, I added a backslash to the quotations marks. Setting the variable is successful. When I run the command from above <code>echo COMMIT | sed "s@COMMIT@${morerules}@g"</code>, this is the output:</p>
  
  <p><code>sed: -e expression #1, char 9: unterminated</code>s' command`</p>
  
  <p>Is the error with my string or with my sed command? Also, I know other people have gotten this error, but none of their fixes seem to work.</p>