why empty line is not getting stored in variable

前端 未结 3 1293
借酒劲吻你
借酒劲吻你 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:59

    empty lines are not there because they are considered whitespaces used to separate word values.

    use this:

    awk '{print $1}' server.txt

     server1.com
     server2.com
    
     server3.com
    
    
     server4.com
    

提交回复
热议问题