为什么我得到“找不到字符串终止符"“"?EOF 之前的任何位置 -e line 1"当我尝试在 Windows 上运行 Perl one-liner 时? [英] 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?
问题描述
我正在尝试使用 5.14.2 在 Windows 上运行以下内容
I am trying to run the following on Windows with 5.14.2
C:Perl>perl -e 'print "Hello World
"'
Can't find string terminator "'" anywhere before EOF at -e line 1.
我错过了什么?
推荐答案
您缺少一个体面的外壳,它具有合理且定义明确的引用规则.在 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
}"
我强烈建议避免使用 Windows 上最简单的单行代码以外的任何内容.(Windows one-liners 的另一个问题是 Windows shell 不扩展通配符.如果您在命令行上使用 *.txt
,它会查找一个名为 * 的文件.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 上,您输入的内容相当于:
On Windows, what you typed is equivalent to:
perl -e "'print" "Hello World
'"
也就是说,Perl 试图执行的代码是 'print
,其中 @ARGV
包含单个字符串 Hello World
'
.(那不是换行符,而是反斜杠后跟 n
).
That is, the code Perl is trying to execute is 'print
with @ARGV
containing the single string Hello World
'
. (That's not a newline, that's a backslash followed by n
).
这篇关于为什么我得到“找不到字符串终止符"“"?EOF 之前的任何位置 -e line 1"当我尝试在 Windows 上运行 Perl one-liner 时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!