I was trying to read a file line by line(each line is a hostname), do some processing like this :
while read -r line
do
if ping -c1 $line
echo $line is running
fi
done <file.txt
I found that the out put is like this:
is running
is running
...
As if the variable $line is empty.
Thanks to all who commented this question. I think I now understand what happened.
So the file has CRLF line ending. And the length of a line is exactly the same as is running.
Because of the CR character at the end of $line, the content of $line gets completely overwritten by is running. If only the length of a line is longer, I would have asked the question differently.