Re: bash "while do echo" can't function correctly

2016-04-13 Thread Greg Wooledge
On Wed, Apr 13, 2016 at 03:28:02PM +0100, Stephane Chazelas wrote: > 2016-04-13 08:55:16 -0400, Greg Wooledge: > [...] > > > And if you want to keep eventual spurious characters after the > > > last NL character in the file: > > > > > > while IFS= read -r line; do printf '%s\n' "$line"; done <

Re: bash "while do echo" can't function correctly

2016-04-13 Thread Stephane Chazelas
2016-04-13 08:55:16 -0400, Greg Wooledge: [...] > > And if you want to keep eventual spurious characters after the > > last NL character in the file: > > > > while IFS= read -r line; do printf '%s\n' "$line"; done < test.txt > > [ -z "$line" ] || printf %s "$line" > > Another way to write that

Re: bash "while do echo" can't function correctly

2016-04-13 Thread Greg Wooledge
On Wed, Apr 13, 2016 at 01:43:42PM +0100, Stephane Chazelas wrote: > 2016-04-13 08:10:15 +0200, Geir Hauge: > [...] > > while read -r line; do echo "$line"; done < test.txt > > > > though printf should be preferred over echo: > > > > while read -r line; do printf '%s\n' "$line"; done <

Re: bash "while do echo" can't function correctly

2016-04-13 Thread Stephane Chazelas
2016-04-13 08:10:15 +0200, Geir Hauge: [...] > while read -r line; do echo "$line"; done < test.txt > > though printf should be preferred over echo: > > while read -r line; do printf '%s\n' "$line"; done < test.txt [...] Actually, you also need to empty $IFS while IFS= read -r line; do

Re: bash "while do echo" can't function correctly

2016-04-13 Thread Greg Wooledge
On Wed, Apr 13, 2016 at 06:49:51AM -0500, John McKown wrote: > ???Ah. Thanks. I only use BASH and the GNU infrastructure, so I have never > run into that problem. I think I'll change my habits, just in case I run > across a system which doesn't have it (especially in my scripts) Every

Re: bash "while do echo" can't function correctly

2016-04-13 Thread John McKown
On Wed, Apr 13, 2016 at 6:45 AM, Pierre Gaston wrote: > > > On Wed, Apr 13, 2016 at 2:34 PM, John McKown > wrote: > >> On Wed, Apr 13, 2016 at 1:10 AM, Geir Hauge wrote: >> >> ​... >> >> >>> though printf should be

Re: bash "while do echo" can't function correctly

2016-04-13 Thread Pierre Gaston
On Wed, Apr 13, 2016 at 2:34 PM, John McKown wrote: > On Wed, Apr 13, 2016 at 1:10 AM, Geir Hauge wrote: > > ​... > > >> though printf should be preferred over echo: >> >> while read -r line; do printf '%s\n' "$line"; done < test.txt >> >

Re: bash "while do echo" can't function correctly

2016-04-13 Thread John McKown
On Wed, Apr 13, 2016 at 1:10 AM, Geir Hauge wrote: ​... > though printf should be preferred over echo: > > while read -r line; do printf '%s\n' "$line"; done < test.txt > ​I've never read about using printf in preference to echo. Why is that? ​I have used it myself

Re: bash "while do echo" can't function correctly

2016-04-13 Thread Geir Hauge
On Wed, Apr 13, 2016 at 10:01:23AM +0800, 何建军 wrote: > Hi, I use a very simple statement "cat test.txt | while read line; do echo > $line; done", test.txt is very small, no more than 100 lines. but the > execution of the statement paused during process. test.txt is pasted on >

bash "while do echo" can't function correctly

2016-04-12 Thread 何建军
Hi, I use a very simple statement "cat test.txt | while read line; do echo $line; done", test.txt is very small, no more than 100 lines. but the execution of the statement paused during process. test.txt is pasted on http://paste.bradleygill.com/index.php?paste_id=1647399