On Fri, Jun 09, 2017 at 08:58:05PM +0300, Pierre Gaston wrote:
> Even if they don't realize it, few people would expect:
>
> var=$(wc -l file);echo "$var"
>
> to print 2 lines.
imadev:~$ file=$'a\nb\nc\nd\ne'; touch "$file"
imadev:~$ var=$(wc -l "$file"); echo "$var"
0 a
b
c
d
e
> Trailing newlines are often not that interesting.
But embedded newlines certainly are!
(Really, though, I know what you meant. Command substitution strips
trailing newlines because that's how it has always worked, and because
95% of the time, that's what you want.)