title: How should I handle errors in ex scripts without waiting for user input?
body: <p>I'm trying to perform a search/replace with an ex script (targeting vim's ex implementation), as so:</p>
  
  <pre><code>ex -qc 'g/^[#][[:space:]]*$/d|x' file.txt
  </code></pre>
  
  <p>However, when <code>file.txt</code> already contains no matching content, the script hangs; when run without <code>-q</code>, it additionally displays the error below:</p>
  
  <pre><code>E486: Pattern not found: ^[#][[:space:]]*$
  </code></pre>
  
  <p>How can I build this script to continue (or, better, abort and immediately exit) on failure, rather than awaiting user input?</p>
  
  <p>I'm using <code>ex</code> in favor of <code>sed -i</code> due to portability constraints (in-place edit support being a GNU extension to sed, and not available on all platforms).</p>