Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
up vote 3 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

Pass the script through dos2unix to fix the newlines.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .