简体   繁体   English

Linux文件上的退格问题

[英]backspace issue on linux file

I use EditPlus to write linux bash programs. 我使用EditPlus编写linux bash程序。 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. 我也使用dos2unix来解决这个问题,但没有成功。 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. 我要解决的问题是我在linux中查看文件,然后逐行从windows文件复制到linux文件,然后就可以了。 these are lines of my code: 这些是我的代码行:

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

You need to change file preferences: go to Preferences -> Files and change "Create new file as " to UNIX. 您需要更改文件首选项:转到首选项 - >文件,然后将“创建新文件”更改为UNIX。 Also, your might want to enable "Check invalid CR/LF, null character when loading" option. 此外,您可能希望启用“检查无效的CR / LF,加载时为空字符”选项。

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. 与类似的程序相比,这不适用于无用的猫奖励,因为tr不接受文件名作为参数。

在VSCode / atom中设置“行结束序列”从CRLF到LF并保存为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM