Fix syntax errors with variable expansion