bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trailing newlines disappear


From: Greg Wooledge
Subject: Re: Trailing newlines disappear
Date: Fri, 9 Jun 2017 14:04:18 -0400
User-agent: Mutt/1.4.2.3i

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.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]