2013-12-03 28 views
2

當我的貓這個文件我得到6線(這是一個差異文件)的bash while循環下降的文本文件的最後一行

bash-3.00$ cat /tmp/voo 
18633a18634 
> sashabSTP 
18634a18636 
> sashatSTP 
21545a21548 
> yheebash-3.00$ 

然而,當我一行行讀它,我只得到5行。

bash-3.00$ while read line ; do echo $line ; done < /tmp/voo 
18633a18634 
> sashaSTP 
18634a18636 
> sashatSTP 
21545a21548 

或本

bash-3.00$ cat /tmp/voo | while read line ; do echo $line ; done 
18633a18634 
> sashabSTP 
18634a18636 
> sashatSTP 
21545a21548 
bash-3.00$ 

我缺少從while循環的最後一行 'yhee'。

回答

5

注:

21545a21548 
> yheebash-3.00$ 
     ^---- no line break 

您的文件不具有換行符終止。

+0

喲得到它 - 輸出是cron驅動 - 我想我會在最後一行添加一個回顯命令。 – capser

+1

你也可以通過使用'while read line ||'來使'while'循環運行於未終止的最終行。 [-n「$ line」]; (參見[這個以前的答案](http://stackoverflow.com/questions/12916352/shell-script-read-missing-last-line/12919766#12919766))。 –

相關問題