Retaining whitespaces...

There's an input file(input.txt) which has the following details :

CBA
 BA

<Please note the second record has a LEADING WHITESPACE which is VALID>
I am using the following code to read the content of the said file line by line:

while read p ; do
   echo "$p"
done < input.txt

This is the output I am getting :

CBA
BA

Note : The leading WHITESPACE in the second record is getting removed automatically when the read command
is retrieving the values and assigning it to the variable "p"

HOW CAN I RETAIN THE LEADING WHITESPACE OF A COMMAND OUTPUT ????
IS IT A DEFAULT FEATURE OF UNIX TO REMOVE ALL LEADING/TRAILING WHITESPACE CHARACTERS WHENEVER A COMMAND ASSIGNS ITS OUTPUT TO A VARIABLE
FROM THE STDOUT ??
HOW TO BYPASS IT ??
This same thing happens for the following command also :

for p in `cat input.txt` ; do
   echo "$p"
done

PLEASE HELP.
Thanks
Kumarjit.

It's a feature of the read builtin. It's designed to split on any characters in the IFS special variable, which default to whitespace, but can be set to whatever you want or even nothing.

Also, you should use read's -r switch, to disable backslash escapes, which read otherwise parses too.

while IFS="" read -r VARNAME
do
        echo "$VARNAME"
done

The for X in `cat file` loop is an even worse idea, because it doesn't split across lines -- it splits across any whitespace.