【发布时间】:2026-02-20 10:30:01
【问题描述】:
当我 cat 这个文件时,我得到 6 行(它是一个 diff 文件)
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”。
【问题讨论】:
标签: bash loops while-loop