why empty line is not getting stored in variable

前端 未结 3 1298
借酒劲吻你
借酒劲吻你 2021-01-28 11:01

I am using below code

    #! /bin/bash
for host in $(cat ./server.txt)
do 
    echo \"$host\"

done

server.txt contains :

              


        
3条回答
  •  我在风中等你
    2021-01-28 11:46

    while read host; do echo "$host"; done < server.txt
    

    With the code you provided, the file as a single string is given as the 4th argument to the for command. The shell then splits the string using arbitrary whitespace as a delimiter (assuming you have not altered the IFS variable).

提交回复
热议问题