title: Check if a file contains a multi-line string in bash
body: <h2>Background</h2>
  
  <p>I am writing a function to append to a file in my <code>$HOME</code> directory called <code>.bash.local</code>. </p>
  
  <p>➡️ <code>.bash.local</code> is sourced via <code>.bash_profile</code>.</p>
  
  <p>However, I want to conditionally append to <code>.bash.local</code> <strong>if and only if</strong> the file <strong>does not</strong> already contain the contents of <code>$BASH_CONFIGS</code>.</p>
  
  <h2>Things to Keep in Mind</h2>
  
  <p>My operating system of choice is <code>MacOS Mojave</code>, thus certain versions of command line applications will be different (e.g. <code>grep</code> on a Mac is <code>BSD grep</code> and not <code>GNU grep</code>).</p>
  
  <h2>⚠️ append_to_bash_local()</h2>
  
  <pre><code>append_to_bash_local() {
      local LOCAL_BASH_CONFIG_FILE="$HOME"/.bash.local
  
      declare -r BASH_CONFIGS="
  # TOOL_NAME - TOOL_DESCRIPTION.
  # Add tool configurations here
  "
  
      # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  
      # If needed, add the necessary configs in the
      # local shell configuration file.
  
      if ! grep "^$BASH_CONFIGS" &lt; "$LOCAL_BASH_CONFIG_FILE" &amp;&gt; /dev/null; then
          # this block never runs, even if the contents of $BASH_CONFIG
          # are NOT present in $HOME/.bash.local
      fi
  
  }
  </code></pre>