意外标记 `$'in\r'' 附近存在语法错误
我正在尝试编译 NIST 生物识别图像软件,但一整天都遇到了麻烦。我终于正确检查了源代码,并且安装了 cygwin 没有任何问题(我过去使用过它),但是当我去编译时,我收到此错误:
$ sh setup.sh </cygdrive/c/NBIS> [--without-X11]
setup.sh: line 94: syntax error near unexpected token `$'in\r''
'etup.sh: line 94: ` case $1 in
现在我确信任何高级编码器都会前往setup.sh 并查找问题,但我并不是一个真正的编码员(我只是编译这个,因为没有预编译的包)所以我不知道该怎么做。我没有使用 cygwin 安装任何库,我只是将所有内容保留为默认值。我正在尝试遵循 NBIS 手册,但我不太理解它,所以我很挣扎。也许看一下它,您可能会注意到我错过了一些东西:http://www.nist.gov/customcf /get_pdf.cfm?pub_id=51097
I'm trying to compile the NIST Biometric Image Software, and I have been having trouble all day. I finally got the source checked out right, and I installed cygwin with no problems (I have used it in the past), but when I went to compile, I get this error:
$ sh setup.sh </cygdrive/c/NBIS> [--without-X11]
setup.sh: line 94: syntax error near unexpected token `
Now I'm sure any advanced coder would head to the setup.sh and look for problems, but I'm not really much of a coder (I'm only compiling this because there are no pre-compiled packages) so I don't know what to do. I didn't install any libraries with cygwin, I just left everything default. I'm trying to follow the NBIS manual, but I don't really understand it that well and so I'm struggling badly. Maybye taking a look at it you may notice something I missed: http://www.nist.gov/customcf/get_pdf.cfm?pub_id=51097
in\r''
'etup.sh: line 94: ` case $1 in
Now I'm sure any advanced coder would head to the setup.sh and look for problems, but I'm not really much of a coder (I'm only compiling this because there are no pre-compiled packages) so I don't know what to do. I didn't install any libraries with cygwin, I just left everything default. I'm trying to follow the NBIS manual, but I don't really understand it that well and so I'm struggling badly. Maybye taking a look at it you may notice something I missed: http://www.nist.gov/customcf/get_pdf.cfm?pub_id=51097
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
运行
来修复你的行结尾
run
to fix your line endings
这是行结束不匹配的症状。
要将
setup.sh
转换为 Cygwin 上的 Unix 行结尾,请使用That's a symptom of line-ending mismatch.
To convert
setup.sh
to Unix line endings on Cygwin, use将 example.sh 文件转换为 unix 的简单方法是使用 NotePad++(编辑>EOL 转换>UNIX/OSX 格式)。
您还可以在 notepad++ 中设置默认 EOL(设置>首选项>新文档/默认目录>选择 Unix/OSX 下的格式框)
Easy way to convert example.sh file to unix is use NotePad++ (Edit>EOL Conversion>UNIX/OSX Format)
You can also set the default EOL in notepad++ (Settings>Preferences>New Document/Default Directory>select Unix/OSX under the Format box)
在 pycharm 中,您可以通过单击屏幕右下角的字母
CRLF
并选择LF
来快速更改行结尾。In pycharm you can quickly change the line endings by clicking on the letters
CRLF
at the bottom right of the screen and selectingLF
.Windows 使用两个字符(CR 和 LF,或
\r\n
)来标记文本文件中的行结束。 Unix、Linux 和(默认情况下)Cygwin 使用单个 LF 或“\n”字符。一些 Cygwin 工具能够处理这两种格式,但 sh 通常不能。看起来
setup.sh
使用了 Windows 风格的行结尾——或者至少第 94 行是这样。我没有找到源文件的下载,但如果它们作为 zip 文件分发,您可能需要使用 Cygwin
unzip
命令和-a
选项,因此任何行结尾都会自动转换。但我怀疑事情远不止于此。分布式
setup.sh
文件一开始就不应该有任何 Windows 风格的行结尾,如果有的话,我不知道为什么问题直到第 94 行才出现如果您可以发布源下载的 URL,我会看一下
setup.exe
。Windows uses two characters (CR and LF, or
\r\n
) to mark the end of a line in a text file. Unix, Linux, and (by default) Cygwin use a single LF or '\n' character. Some Cygwin tools are able to deal with either format, but sh typically can't.It looks like
setup.sh
uses Windows-style line endings -- or at least line 94 does.I didn't find the download for the sources, but if they're distributed as a zip file, you might need to extract them using the Cygwin
unzip
command with the-a
option, so any line endings are automatically converted.But I suspect there's more to it than that. The distributed
setup.sh
file shouldn't have had any Windows-style line endings in the first place, and if it did, I don't know why the problem wouldn't show up until line 94.If you can post the URL for the source download, I'll take a look at
setup.exe
.我曾经遇到过同样的问题,但我使用记事本++解决了它
安装记事本++,使用记事本++打开你的shell代码,转到“编辑”菜单,选择“EOL转换,选择“Unix(LF)”选项,它应该被修复
或者,如果您使用 Visual Studio Code,则可以将
CRLF
更改为LF
视觉Studio代码
Notepad++
I used to have the same issue but I solved it using notepad++
Install Notepad++, Open your shell code using Notepad++, Go to the "Edit" menu, Select "EOL Conversion, Choose the "Unix (LF)" option and it should be fixed
or if you use Visual Studio Code you can change
CRLF
toLF
Visual Studio Code
Notepad++
我遇到了同样的问题。我使用的是 Windows 11、WSL 和 Ubuntu 发行版。
这个错误是由于脚本是在Windows机器上编辑的,它使用回车符(\r)和换行符(\n)作为行结尾,而基于Unix的系统(如Linux)仅使用换行符( \n)。
我通过使用 dos2unix 命令解决了这个问题。
以下是具体操作方法。
只要跑:
就你的情况而言。
注意:您可能需要通过运行
sudo apt install dos2unix
来安装dos2unix
I came across the same issue. I am using Windows 11, with WSL and Ubuntu distro.
This error is due to the fact that the script was edited on a Windows machine, which uses carriage return (\r) and line feed (\n) as line endings, while Unix-based systems (like Linux) only use line feed (\n).
I fixed this problem by using the
dos2unix
command.Here is how to do it.
Just run:
In your case.
NB: You may need to install
dos2unix
by runningsudo apt install dos2unix