11

I use EditPlus to write linux bash programs. after writting when i move files to server i get these kind of errors:

sleep: invalid time interval `2\r'
Try `sleep --help' for more information.

/usr/bin/program: line 9: $'\r': command not found
/usr/bin/program: line 10: $'}\r': command not found
/usr/bin/program: line 11: $'\r': command not found
/usr/bin/program: line 12: syntax error near unexpected token `$'{\r''
'usr/bin/program: line 12: `stop() {

I have also used dos2unix to fix this issue but no success. I want to know that is there any way that I can avoid this kind of problems. it waste alot of time. is there any better editor or some way to fix this issue?

EDIT:

What I do to solve this issue is that I vi a file in linux and then copy line by line from windows file to linux file and then it works. these are lines of my code:

line7:udevadm control --reload-rules sleep 2 echo echo $(date +"%b %e %T") hostname Program[$$]: Program Started | tee -a /var/log/messages echo } stop() {

user115079
  • 711
  • 1
  • 11
  • 23
  • I've never used EditPlus before, but [Wikipedia claims](http://en.wikipedia.org/wiki/EditPlus) that it has a line-ending converter built in. Have you looked for one? – Tim Pote May 04 '12 at 18:39
  • consider editing your post to include lines 9-12 of the script that is causing problems. That sure looks like a `dos2unix` solvable problem. Also, use `cat -vet file` to see ctrl-chars embedded in your script. You shouldn't see anything like ^A-^Z in the file. Good luck. – shellter May 04 '12 at 18:40
  • 2
    Btw.: That isn't a backspace, but the carriage-return (alias: return, hence \r) from the CR-LF combo. Backspace would be \b. – user unknown May 04 '12 at 22:50

3 Answers3

11

You need to change file preferences: go to Preferences -> Files and change "Create new file as " to UNIX. Also, your might want to enable "Check invalid CR/LF, null character when loading" option.

BluesRockAddict
  • 15,525
  • 3
  • 37
  • 35
4

For already produced files

cat OLDFILE | tr -d '\r' > NEWFILE 

should help. You can't just redirect the output to the input:

cat FILE | tr -d '\r' > FILE 

since this will truncate the input file before it is read.

In contrast to similar programs, this is not eligible for the useless-use-of-cat award, since tr doesn't accept a filename as parameter.

user unknown
  • 35,537
  • 11
  • 75
  • 121
3

Setting the "line ending sequence" in VSCode / atom from CRLF TO LF and saving worked for me

Marc Sloth Eastman
  • 693
  • 1
  • 10
  • 19