I am new to shell script. I am sourcing a file, which is created in Windows and has carriage returns, using the source
command. After I source when I append some characters to it, it always comes to the start of the line.
test.dat
(which has carriage return at end):
testVar=value123
testScript.sh
(sources above file):
source test.dat echo $testVar got it
The output I get is
got it23
How can I remove the '\r'
from the variable?
vi. You can even remove carriage return (Ctrl+M) characters with vi, although this assumes you're not running through hundreds of files and are maybe making some other changes, as well.
yet another solution uses tr
:
echo $testVar | tr -d '\r' cat myscript | tr -d '\r'
the option -d
stands for delete
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With