how can i do some action when 'ctrl+d' is pressed

hi Gurus, please why is this happening:
when i run this:

#!/bin/bash
declare -a name
declare -a ph
declare -a eid
r=0;
c=1;
i=1;
n=;
echo "         name    phone    email_id"    
while :
do
 #if [ $i>$n ]; then
   #break;
 #else  
   echo -n "field $i:"; read name[$r$c] ph[$r$c] eid[$r$c];
   let "i++";
   let "c++";
 #fi
done
#echo "the values of fields are :"

#for((i=1;i<=n;i++))
#do
 # echo "field$i:${fld[$r$i]}    ${typ[$r$i]}    ${con[$r$i]}" 
#done

when i keep on entering the values, the while loop runs uptil c=7 for c=8 it gives error like:

prayush@prayush-desktop ~/Desktop $ grun.bash ./ex2
         name    phone    email_id
field 1:abc    4327543 jhasdf@fdsj
field 2:sdf 23553    asf@sgfdfg
field 3:adsf    578543    asdfjdsaf
field 4:ahdfjhjk    4795636    gfhdhsdh
field 5:hretiuewndf    9805687954      fdsfjkfkj
field 6:asdfadsf
field 7:
field 8:
./ex2: line 15: 08: value too great for base (error token is "08")

when in Ist code ,if i make r=1, then it becomes an infinite loop. secondly when i uncomment if-else & for code in the script it skips the code with in 'else' and put null in the array variables .
still the problem of "value too great for base (error token is "08")" remains the same for r=0 & n>=8,for r=1 & n>=8 the 'while loop' breaks as per the condition.

heres the output:

 prayush@prayush-desktop ~/Desktop $  ./ex2
         name    phone    email_id
the values of fields are :
field1:        
field2:        
field3:        
field4:        
field5:        
field6:        
field7:        
./ex2: line 24: 08: value too great for base (error token is "08")

what i actually wanted to do was, to read the values of variable until ctrl+d or ctrl+c or may be with any combination with 'ctrl' or 'Alt' if u can suggest. And when this shortkey is pressed i want to perform some custom actions.

You use 01 02 03 04 .. 07 as array indices, which is unusual. I suspect these number get interpreted as octal numbers instead of decimal numbers, hence 08 would be to big for the base and it should be 10 (equals decimal 8).

thanks scruitizer!! that could be the case!!!!!!
But what about the problem of skipping the code when i uncomment 'if-else & for' code. the script is behaving differently!!

Hi tprayush,

You are doing a lexicographical comparison (">") instead of a numerical comparison ("-gt"). So instead of

if [ $i>$n ]; then

you should use

if [ $i -gt $n ]; then

or preferably:

if [[ $i -gt $n ]]; then

or use an arithmetic evaluation:

if (( i > n )); then

thanks Scrutinizer for your help..
but i don't get the meaning of 'lexicographical comparison`!!!

Alphabetical or "dictionary" order, typically it means using ASCII ordering.
so e.g. 100<2<23<39<4, whereas the numerical order is 2<4<23<39<100.