Extra characters being added to the variable that is extracted from the server

git checkout ${out};

when I use the above command trying to checkout to out variable, its giving an error and the error is because an extra grabage value or ? is being added to the variable. how to remove that?

The issue you’re experiencing might be due to hidden characters or whitespace in your out variable.
You could use the tr command to delete these unwanted characters.
Here’s how you could do it:

out=$(echo "${out}" | tr -d '\n' | tr -d '\r')
git checkout "${out}"

In this code, tr -d '\n' removes newline characters, and tr -d '\r' removes carriage return characters.
After this operation, you should be able to use the out variable without any issues… or find it’s another character that gives you trouble. :person_shrugging:

1 Like