Use Bash to read line by line and keep space

后端 未结 6 885
感情败类
感情败类 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:27

    read data will split the data by IFS, which is typically " \t\n". This will preserve the blanks for you:

    var=$(cat test.file)
    echo "$var"
    

提交回复
热议问题