backspace issue on linux file

2019-04-28 02:59发布

问题:

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() {

回答1:

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.



回答2:

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.