Problem assigning the DID to variable in a call file

I cannot figure out how to create a call file that will assign the value of the DID dialed by the user to the variable F_DID. Could you please help me? You will find below the relevant Asterisk extension and the body of my callfile. My server runs Centos 5.2 and Asterisk 1.6.

Thanks,

Normand

exten => s,n,System(/bin/bash /etc/asterisk/callfile.sh ${CALLERID(num)} ${CALLERID(num)}_${EPOCH}.callfile ${F_language} ${F_wait} ${F_status} ${F_longdistance} new_callback 1)


CONTENT OF THE FILE : callfile.sh

arg1 is the phone number to call

arg2 is the spool file name

arg3 if the user’s language

arg4 is the dalay for the callback

arg5 is the client status

arg6 is the long distance status

arg7 is the context to use for the callback

arg8 is the retry counter

#echo “Channel: DAHDI/g7/$1” >/tmp/$2
echo “Channel: Local/$1@dial2group” >/tmp/$2
echo “MaxRetries: 6” >>/tmp/$2
echo “RetryTime: 5” >>/tmp/$2
echo “WaitTime: 50” >>/tmp/$2
echo “Context: $7” >>/tmp/$2
echo “Extension: s” >>/tmp/$2
echo “Priority: 1” >>/tmp/$2
echo “Setvar: F_language=$3” >>/tmp/$2
echo “Setvar: F_status=$5” >>/tmp/$2
echo “Setvar: F_longdistance=$6” >>/tmp/$2
echo “Setvar: registration_clid=$1” >>/tmp/$2
echo “Setvar: MyRetryCallback=$8” >>/tmp/$2

chown asterisk:asterisk /tmp/$2
chmod 777 /tmp/$2
newdate=date --date "$dte $4 sec"
touch --date="$newdate" /tmp/$2
mv /tmp/$2 /var/spool/asterisk/outgoing