There are a few ways to read a file in bash, each with their own caveats. If you’re looking to read a file line-by-line verbatim, including blank lines, then using a simple
while loop should do the trick. For example, the following code will print the contents of a file with line numbers:
while IFS='' read -r line
echo "$line_no: $line"
done < /etc/kderc
This will print something like: