On Fri, Jun 09, 2017 at 12:38:19AM +0700, PePa wrote: > I would think this is a bug:
> 4.3.48(1)-release> printf "q\n\n\n" >w > 4.3.48(1)-release> printf "$(cat w)" > q > 4.3.48(1)-release> > > Is there some workaround to somehow preserve the trailing newlines? It's not a bug. This is how command substitution has worked since the original Bourne shell. The workaround is to put something inside the command substitution, so that the newlines aren't trailing any more, and then strip it away afterward: foo=$(cat "$file"; printf x) foo=${foo%x} This also means that you can't use the $(< "$file") shortcut any more, if you need to preserve the full contents of a file.