Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here is my bash script that is sent a variable from php:

STRING1="/opt/lampp/htdocs/dev/img/$VAR1"
mv $STRING1 "/opt/lampp/htdocs/dev/newlocation/"

It, for some reason, places "\r" at the end of $STRING1 and can't find the file because it will be something of the form "my_picture.jpg\r"

Any help is appreciated!

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Bash expects that end-of-line in a script is always and only a newline (\n) character, Unix-style, not a carriage return-newline combination (\r\n) like you normally see on Windows. Bash thinks the \r character is just an ordinary character at the end of the string. (Characters that follow a double quoted string are just concatenated onto the end.)

As Ignacio suggests, the solution is to fix your script to eliminate the \r characters. dos2unix is one way. Another would be to use tr -d '\r' < infile > outfile as a filter.

share|improve this answer
add comment

Pass the script through dos2unix to fix the newlines.

share|improve this answer
1  
And then switch to a text editor that doesn't use DOS-style line endings. –  Gordon Davisson Oct 18 '12 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.