creating dynamic shell script

Hello

I am trying to create a dynamic ksh script and I have an issue.

I have a script a.ksh and it has got the following lines (for example)

#!/bin/ksh
# trace mode +x : without trace -x : with trace
set +xv
echo hi, i am going to create a dynamic script now
cat >> dynamic.ks <<EOF
#!/bin/ksh
# trace mode +x : without trace -x : with trace
set +xv
###################################################################################################
echo $PATH
ses_exi=$(somefileexcution|grep "somevalue"|wc -1)
if [ "$ses_exi" -eq "1" ]
then 
   echo i can open a new session
else
   echo i cannot open a new session
fi
###################################################################################################
EOF

The dynamic file is getting created but look at the file content, its not the same instead the output of each statement execution. I want the same text that I mention in the code. Any help would be appreciated.

#!/bin/ksh
# trace mode +x : without trace -x : with trace
set +xv
###################################################################################################
echo /usr/local/bin/ssh:/home/bdrhom01/outils/curl-7.15.1/bin:/etc:/usr/lib:/usr/openwin/bin:/bin:/usr/bin:/usr/sbin:.:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/sfw/bin:/usr/ucb:/usr/local/bin:/bdrhomtt01/oracle/product/10.2.0.3/bin:/home/bdrhom01/ccm_tools:/tools/ccm63/bin:/home/bdrhom01/bin:/home/bdrhom01/outils:/home/bdrhom01
ses_exi=       0
if [ "" -eq "1" ]
then
   echo i can open a new session
else
   echo i cannot open a new session
fi
###################################################################################################

Many thanks in advance
Sundar

Try escaping all $ expressions with a backslash (\). ie, \$ses_exi.

Thanks and it works