Rearrange the scripts (stop using a here document).