Variable Initialize

Hi, i m trying to loop a variable value, Basically i m reading variable value from an input file and using in rest of the program. Bu my problem is when i first time read value and assign to variable it works fine, but in second read it concatinate second value to first value with a LF. I want to use one value at a time. Here is what i am doing

carrier_id=`cat ${cnt_path}mpd_rxsh_carrier_id.dat | head -${i}`
Value::
1st read
253090
2nd read
253090
253029
3rd read
253090
253029
255055

my input file mpd_rxsh_carrier_id.dat is like
253090
253029
255055

Please let me know how i can initialize a variable to hold only new value or there is any other way to do this.

thanks

Your error is quite obvious. Your loop variable is 'i', and as the value of i increases, head -${i} returns more and more lines. Let me explain.

At your first pass through the loop, the value of i is 1. You get the first line. So far so good. At the second pass the value of i becomes 2 and head -${i} becomes head -2, which returns the first two lines.. this will continue as long as the value of i increases.

If you want to read the value of carrier id from the file into variable carrier_id, you have to use

while read carrier_id;do
..
# do your stuff here
..
done < ${cnt_path}mpd_rxsh_carrier_id.dat

Thanks Buddy...It works...After posting my query i realize tht head is not meant for it...

Thanks for giving the best solution.