bash 尝试在 cygwin 中运行脚本时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20713152/
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
error while trying to run a script in cygwin
提问by littlerunaway
unexpected end of file. now I did a search on the error and I understand that my script file (that was created in windows) has wrong endings. I also read that I can use dos2unix command on the file to fix this. however, I've tried that and cygwin tells me:
意外的文件结尾。现在我对错误进行了搜索,我知道我的脚本文件(在 Windows 中创建)有错误的结尾。我还读到我可以在文件上使用 dos2unix 命令来解决这个问题。但是,我已经尝试过了,cygwin 告诉我:
-bash: dos2unix: command not found
other than cygwin I work on a remote unix terminal, on which my script runs fine and there is even a dos2unix command. I've used it on the script file, and tried to use the converted file in cygwin with the same unexpected end of file error. so what are my options?
除了 cygwin,我在远程 unix 终端上工作,我的脚本在该终端上运行良好,甚至还有一个 dos2unix 命令。我已经在脚本文件上使用了它,并尝试在 cygwin 中使用转换后的文件,但同样出现意外的文件结尾错误。那么我的选择是什么?
回答by glenn Hymanman
You can install dos2unix
from the cygwin setup utility
您可以dos2unix
从 cygwin 安装实用程序安装
But, this should work too:
但是,这也应该有效:
sed -i 's/\r$//' file
However, "unexpected end of file" often means you have an open quote (or brace or parenthesis) with no close quote (or brace or parenthesis)
但是,“意外的文件结尾”通常意味着您有一个开引号(或大括号或括号)而没有右引号(或大括号或括号)