Use Bash to read line by line and keep space

后端 未结 6 890
感情败类
感情败类 2020-11-28 05:00

When I use \"cat test.file\", it will show

1
 2
  3
   4

When I use the Bash file,

cat test.file |
while read data
do
    e         


        
6条回答
  •  心在旅途
    2020-11-28 05:30

    Actually, if you don't supply an argument to the "read" call, read will set a default variable called $REPLY which will preserve whitespace. So you can just do this:

    $ cat test.file | while read; do echo "$REPLY"; done
    

提交回复
热议问题