title: Is there an easy way to pass a "raw" string to grep?
body: <p><code>grep</code> can't be fed "raw" strings when used from the command-line, since some characters need to be escaped to not be treated as literals. For example:</p>
  
  <pre><code>$ grep '(hello|bye)' # WON'T MATCH 'hello'
  $ grep '\(hello\|bye\)' # GOOD, BUT QUICKLY BECOMES UNREADABLE
  </code></pre>
  
  <p>I was using <code>printf</code> to auto-escape strings:</p>
  
  <pre><code>$ printf '%q' '(some|group)\n'
  \(some\|group\)\\n
  </code></pre>
  
  <p>This produces a bash-escaped version of the string, and using backticks, this can easily be passed to a grep call:</p>
  
  <pre><code>$ grep `printf '%q' '(a|b|c)'`
  </code></pre>
  
  <p>However, it's clearly not meant for this: some characters in the output are not escaped, and some are unnecessarily so. For example:</p>
  
  <pre><code>$ printf '%q' '(^#)'
  \(\^#\)
  </code></pre>
  
  <p>The <code>^</code> character should not be escaped when passed to <code>grep</code>.</p>
  
  <p>Is there a cli tool that takes a raw string and returns <strong>a bash-escaped version of the string that can be directly used as pattern with grep</strong>? How can I achieve this in pure bash, if not?</p>