The last technique might be needed if your script writes another script, say for overnight batch processing, in which you want a command to be evaluated when the second script is run, not the first. You can also write files within this second script, provided you choose different words to delimit the file contents. Here's an example which combines both of these techniques.
cat >! /tmp/${user}_batch_${runno}.csh <<EOF
#!/bin/csh
# Create the data file.
cat >! /tmp/${user}_data_${runno} <<EOD
$runno
\`date\`
`star/bin/kappa/calc exp="LOG10($C+0.01*$runno)"`
EOD
<commands to perform the data processing using the data file>
# Remove the temporary script and data files.
rm /tmp/${user}batch_${runno}.csh
rm /tmp/${user}_data_${runno}
exit
EOF
chmod +x /tmp/${user}_batch_${runno}.csh
This excerpt writes a script in the temporary directory. The
temporary script's filename includes our username ($user) and
some run number stored in variable runno. The temporary script
begins with the standard comment indicating that it's a C-shell
script. The script's first action is to write a three-line data file.
Note the different delimiter, EOD. This data file is created
only when the temporary script is run. As we want the time and date
information at run time to be written to the data file, the command
substitution backquotes are both escaped with a \. In
contrast, the final line of the data file is evaluated before the
temporary script is written. Finally, the temporary script removes
itself and the data file. After making a temporary script, don't
forget to give it execute permission.
C-shell Cookbook