title: Bash script too slow as string variable grows
body: <p>The input file ($1) is a mbox file (which is a text file).
  The idea is to read it from the beginning, save a message in $message, do something with it, discard it and start all over again.
  The problem now is that the more the message is large and the more the script slows down.
  The script always hangs when it reaches a 10mb message, which I calculated it would take at least 20 minutes.</p>
  
  <pre><code>message=''
  IFS_old=$IFS
  IFS=''
  while read -r line; do
      if [[ "$line" =~ ^From\ .* ]]; then
          message="$line"
      else
          message+=$'\n'"$line"
      fi
  done &lt; "$1"
  IFS=$IFS_old
  </code></pre>
  
  <p>You just comment the line</p>
  
  <pre><code>message+=$'\n'"$line"
  </code></pre>
  
  <p>and in one minute the script finishes with a 120mb mbox file.
  Is it bad to expect a variable to hold few mb?
  Thank you all</p>