backspace issue on linux file

戏子无情 提交于 2019-12-10 02:36:54

问题


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.




回答3:


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



来源:https://stackoverflow.com/questions/10454309/backspace-issue-on-linux-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!