How to remove duplication in Bash scripts