Optimize bash code