Running latest version of Rasbian and using RPI Camera, I want to build a script that takes picture each 10min and upload to a webserver. I started with taking the picture.

When I run the command from the prompt it executes fine and the file looks good

pi@raspberrypi ~ $ raspistill -w 1024 -h 768 -o test.jpg

Looks like this: test.jpg

When I run it like a script (camera.sh) with the same commands the file looks strange:

raspistill -w 1024 -h 768 -o test.jpg

Looks like this: test.jpg\r

What am I doing wrong?

  • 2
    what editor did you use to write the script? It looks like it may have added Windows line endings. – rob Mar 12 '15 at 8:27
  • 2
    Agree to @rob. Try running dos2unix on that file before execution. – user236012 Mar 12 '15 at 10:11
  • I rewrote the script in NANO and now it´s working so I guess @rob conclusion was correct. Thx for the quick answers – Nicole Svensson Mar 12 '15 at 12:22

As per the comments, this has probably happened because you wrote the script on a windows machine. Windows/DOS uses 2-byte CRLF ("carriage-return line-feed", aka. \r\n) line endings for text, whereas unix derived systems use 1 byte (just the \n). This is why if you read text written on a unix derived system on a DOS system there may appear to be no line breaks (I don't know if some windows tools now automatically compensate for this).

Wheras the other way around, there are line breaks, plus an extra character (\r) at the end.

dos2unix converts one way and unix2dos converts the other. They are in a package together on Raspbian:

sudo apt-get install dos2unix

By default they overwrite the modified file. If you want to copy instead, use -n, as in dos2unix -n [source file] [copy name]. See man dos2unix for more after you install -- but it is pretty simple.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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