How to remove carriage return from a variable in shell script June 7, 2023 by Tarik yet another solution uses tr: echo $testVar | tr -d '\r' cat myscript | tr -d '\r' the option -d stands for delete.