gpt4 book ai didi

vim - 为什么在 Windows 上的 ubuntu 上 bash 仍然使用 CRLF 作为行尾

转载 作者:行者123 更新时间:2023-12-05 03:10:09 24 4
gpt4 key购买 nike

我认为 Windows 上 Ubuntu 上的 bash 应该使用 LF 作为行尾,但我错了。它似乎也像在 Windows shell 上一样使用 CRLF。当我处理它时,我得到了^M 来自 git diff 的问题是这样的:

-            srv.save(name, atrbts);
+ if (gm.isMailboxEnable()) {^M
+ srv.createMailGroup(name, atrbts);^M
+ } else {^M
+ srv.save(name, atrbts);^M
+ }^M

我知道问题所在。我的意思是,Windows 上 Ubuntu 上的 bash 应该使用 LF 作为行尾而不是 CRLF,对吗?

更新:

我犯了一个错误,我在 Bash 中打开了一个特定的 dos 格式文件,Vim 自动检测它然后使用 CRLF 作为行尾。所以问题关闭了。

我在 Vim 中使用 :set ff 命令,它的输出是 fileformat=dos 然后我发现了我的错误。我可以使用 dos2unix 命令来修复这个问题。

最佳答案

这可能是为了确保 windows bash 和在 Windows 操作系统 上创建的文本文件 之间的兼容性。这就是为什么它使用 CRLF 作为新行。

常用表示列表:

LF: Unix and Unix-like systems (Linux, OS X, FreeBSD, Multics, AIX, Xenix, etc.), BeOS, Amiga, RISC OS, and others.

CR+LF: Microsoft Windows, DOS (MS-DOS, PC DOS, etc.), DEC TOPS-10, RT-11, CP/M, MP/M, Atari TOS, OS/2, Symbian OS, Palm OS, Amstrad CPC, and most other early non-Unix and non-IBM OSes

CR: Commodore 8-bit machines, Acorn BBC, ZX Spectrum, TRS-80, Apple II family, Oberon, the classic Mac OS up to version 9, MIT Lisp Machine and OS-9

RS: QNX pre-POSIX implementation

0x9B: Atari 8-bit machines using ATASCII variant of ASCII (155 in decimal)

LF+CR: Acorn BBC and RISC OS spooled text output.

您可以将 Windows Bash 添加到 CR+LF 的列表中。

关于vim - 为什么在 Windows 上的 ubuntu 上 bash 仍然使用 CRLF 作为行尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com