linux 文件退格问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10454309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
backspace issue on linux file
提问by user115079
I use EditPlus to write linux bash programs. after writting when i move files to server i get these kind of errors:
我使用 EditPlus 编写 linux bash 程序。在将文件移动到服务器时写入后,出现以下错误:
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?
我也使用 dos2unix 来解决这个问题,但没有成功。我想知道有什么方法可以避免此类问题。它浪费了很多时间。有没有更好的编辑器或某种方法来解决这个问题?
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:
我为解决这个问题所做的是在 linux 中 vi 一个文件,然后从 windows 文件逐行复制到 linux 文件,然后它就可以工作了。这些是我的代码行:
line7:udevadm control --reload-rules
sleep 2
echo
echo $(date +"%b %e %T") hostname
Program[$$]: Program Started | tee -a /var/log/messages
echo
}
stop() {
line7:udevadm control --reload-rules sleep 2 echo echo $(date +"%b %e %T") hostname
Program[$$]: Program Started | tee -a /var/log/messages echo } stop() {
采纳答案by BluesRockAddict
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.
您需要更改文件首选项:转到首选项 -> 文件并将“创建新文件为”更改为 UNIX。此外,您可能希望启用“加载时检查无效的 CR/LF,空字符”选项。
回答by user unknown
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.
与类似程序相比,这不符合 useless-use-of-cat 奖的条件,因为tr
它不接受文件名作为参数。
回答by Marc Sloth Eastman
Setting the "line ending sequence" in VSCode / atom from CRLF TO LF and saving worked for me
在 VSCode / atom 从 CRLF 到 LF 中设置“行结束序列”并保存对我有用