refine heredoces to handle issues in sudo commands