Search code examples
pythonbashvariablescarriage-return

Bash Variable Contains '\r' - Carriage Return Causing Problems in my Script


I have a bash script (rsync.sh) that works fine and has this line in it:

python /path/to/rsync_script.py $EMAIL "$RSYNC $PATH1 $PATH1_BACKUP"

I want to break the command (it's actually much longer than shown here because my variables have longer names) in two and use something like this:

python /path/to/rsync_script.py \
$EMAIL "$RSYNC $PATH1 $PATH1_BACKUP"

But when I do this I get the error:

scripts/rsync.sh: line 32: $'admin@mydomain.com\r': command not found

It puts the carriage return, \r in there.

How can I break this line up and not include the carriage return?


Solution

  • So I figured it out... I made a mistake in this question and I got so much awesome help but it was me doing a dumb thing that caused the problem. As I mentioned above, I may have copied and pasted from Windows at some point (I had forgotten since I did most of the edits in vim). I went back and wrote a short script with the essentials of the original in vim and then added in the '\' for line break and the script worked just fine. I feel bad accepting my own answer since it was so stupid. I made sure to up-vote everyone who helped me. Thanks again.