为什么我得到“无法找到字符串终结符”“”在EOF之前的任何地方在-e线1“当我试图在Windows上运行Perl一线程? [英] Why am I getting "Can't find string terminator "'" anywhere before EOF at -e line 1" when I try to run a Perl one-liner on Windows?
问题描述
我试图在Windows上运行以下5.14.2
I am trying to run the following on Windows with 5.14.2
C:\Perl>perl -e 'print "Hello World \n"'
Can't find string terminator "'" anywhere before EOF at -e line 1.
我缺少什么? p>
What am I missing?
推荐答案
你失去一个体面的外壳与完美定义的引用规则。在Windows上,只有双引号被视为引号,转义规则定义不完整和不一致。尝试:
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:
perl -e "print qq{Hello World \n}"
我强烈建议避免任何东西,但在Windows上最简单的一行。 (Windows的另一个问题是Windows shell不扩展通配符,如果在命令行中使用 *。txt
,它会查找一个文件
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.)
在Windows上,输入的内容是: * .txt
等于:
On Windows, what you typed is equivalent to:
perl -e "'print" "Hello World \n'"
也就是说,Perl尝试执行的代码是'print
包含单个字符串 Hello World \\\
的c $ c> @ARGV 。 (这不是换行符,反斜杠后面跟
' n
)。
That is, the code Perl is trying to execute is 'print
with @ARGV
containing the single string Hello World \n'
. (That's not a newline, that's a backslash followed by n
).
这篇关于为什么我得到“无法找到字符串终结符”“”在EOF之前的任何地方在-e线1“当我试图在Windows上运行Perl一线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!