为什么我收到“找不到字符串终止符”“” -e line 1" 处 EOF 之前的任意位置当我尝试在 Windows 上运行 Perl 单行代码时?
我尝试在 Windows 5.14.2 上运行以下命令,
C:\Perl>perl -e 'print "Hello World \n"' Can't find string terminator "'" anywhere before EOF at -e line 1.
我缺少什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您缺少一个像样的外壳,具有健全且定义明确的引用规则。在 Windows 上,只有双引号才被视为引号,并且转义规则定义不明确且不一致。尝试:
我强烈建议避免在 Windows 上使用除最简单的俏皮话以外的任何内容。 (Windows 语句的另一个问题是 Windows shell 不扩展通配符。如果您在命令行上使用
*.txt
,它会查找字面上名为* 的文件.txt
。稍后您会遇到它。)在 Windows 上,您键入的内容相当于:
也就是说,Perl 尝试执行的代码是
'print
和@ARGV
包含单个字符串你好世界\n'
。 (这不是换行符,而是一个反斜杠后跟n
)。You're missing a decent shell with sane and well-defined quoting rules. On Windows, only the double quote is considered a quote, and the escaping rules are poorly defined and inconsistent. Try:
I strongly recommend avoiding anything but the very simplest one-liners on Windows. (Another problem with Windows one-liners is that the Windows shell doesn't expand wildcards. If you use
*.txt
on the command line, it'll look for a file named literally*.txt
. You'll run into that later.)On Windows, what you typed is equivalent to:
That is, the code Perl is trying to execute is
'print
with@ARGV
containing the single stringHello World \n'
. (That's not a newline, that's a backslash followed byn
).在 Windows 上,引号应该颠倒。所以,而不是:
它应该是:(
归属学习Perl,第六版,第 295 页)
On Windows, the quotation marks should be reversed. So, rather than:
it should be:
(attribution Learning Perl, 6th edition, p. 295)
我也发现这很有效。我正在使用 Windows 7,使用
c:\Windows\system32\cmd.exe
我在 print 语句中使用转义斜杠来显示引号 \"
I also found this to work. I am using Windows 7 using
c:\Windows\system32\cmd.exe
I'm using the escape slash in my print statement to get the quotes to appear \"
在 Windows 上,以下命令有效:
perl -e "print \"Hello world\""
On Windows the following command works:
perl -e "print \"Hello world\""