cook.sh: separate reading and output of template in separate phases