I am trying to create a simple Linux BASH script but notice that bash is adding \r to every string, and if I try to remove it with 'tr' then it just add a new one! Here's my script
#!/bin/bash
OUTFILE=$(echo -n `date +"%Y-%m-%d_%H-%m-%S"`)
ASD='DDD'
echo -n "DATE [$OUTFILE]"
echo -n "DDD [$ASD]"
and here is the output
bash -x backup-datadir.sh
+++ date +%Y-%m-%d_%H-%m-%S
++ echo -n 2020-03-09_13-03-44
+ OUTFILE=$'2020-03-09_13-03-44\r'
+ ASD=$'DDD\r'
' echo -n 'DATE [2020-03-09_13-03-44
' echo -n 'DDD [DDD-03-44
Why is that extra \r appearing? The ] is gone because it is overwritten after the newline. I've never seen this before...
cat -vetto see these.CR's in eachecho, and no actual newlines./bin/bash: not foundcaused by \r on the shebang. So I was fairly sure that the shebang was edited in separately. But no: it is being explicitly run by a bash command, so the shebang is just a comment, so a \r makes no difference. And why use a .sh extension? Windows continues its malign influence in so many ways.