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