Reading file line by line (with space) in Unix Shell scripting - Issue

后端 未结 2 1731
时光取名叫无心
时光取名叫无心 2020-12-08 15:59

I want to read a file line by line in Unix shell scripting. Line can contain leading and trailing spaces and i want to read those spaces also in the line. I tried with \"whi

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 16:17

    Try this,

    IFS=''
    while read line
    do
        echo $line
    done < file.txt
    

    EDIT:

    From man bash

    IFS - The Internal Field Separator that is used for word
    splitting after expansion and to split lines into words
    with  the  read  builtin  command. The default value is
    ``''
    

提交回复
热议问题