Bash script optimization