Use temp file to handle large commands/scripts
Refactor to avoid duplication