For loop respects quotes but not in a variable

The way i wrote it the (unquoted) blank is a "terminal" (an expression ending the current parsing entity) - several consecutive terminals produce empty parsing entities, unless explicitly suppressed. You can do that in the " " part of the case-construct by inserting something like:

      " ")
          if [ -n "$chBuffer" ] ; then
               # output/process the buffer which just ended
          else
               # do nothing
          fi
          ;;

As for a little theory behind all that: i suggest the "Dragon Book": "Principles of Compiler Design"; Sethi, Aho, Ullmann. IMHO a must for the library of any programmer. It should be the third book apprentices buy, after the TAOCP by Knuth and "The C Programming Language" by Kernighan/Ritchie.

It is a - rather common - misconception that quoting can in any way be nested. I can not! In fact the shell works the same way as my parser: it maintains a flag "inside/outside quoted string" which is switched upon every occurrence of a quote (bar escaping, etc.). So "...."...."....." is read: inside quotes after first, outside after second, inside after third and outside again after fourth quote char.

A single quote inside a double-quoted string (and vice versa) is treated as a normal character without any special meaning.

I hope this helps.

bakunin