Git的换行字符。(Git de huàn xíng zì fu)
在Windows的Linux虚拟环境中,脚本出现错误。
在其他环境中可以运行的,但是……
line 2: $'\r': command not found
line 5: $'\r': command not found
line 35: syntax error near unexpected token `$'do\r''
line 35: `do
「\r\n」中的 “\r” 看起来出现了问题。因为 “\r\n” 是 Windows 的换行符号。
在 Linux 虚拟环境中可能无法使用。
所以,为什么会变成这样呢?
当在Windows上进行Git pull时,换行符会被修改。
$ git config --global -l
core.autocrlf=true
對於Windows環境而言,如上所述,會自動轉換換行符號。
git config --global core.autocrlf false
必须将 autocrlf 禁用,就像上述那样。
脚本本身的换行代码是怎样的。
cat -e {file}
可以通过这种方式确认。
如果在行的末尾出现了”^M”,那么就表示这是Windows换行符代码。