Fixed variable expansion bug in bash script