wal*_*nut 2 powershell perl windows-8
我试图在Windows 8中的PowerShell中从命令行运行多个Perl命令.
这有效
perl -e "print 'Joe'";
Run Code Online (Sandbox Code Playgroud)
这打印:
Joe
Run Code Online (Sandbox Code Playgroud)
这不起作用
perl -e "my $string = 'Joe'; print $string;"
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误
perl : syntax error at -e line 1, near "my ="
At line:1 char:1
+ perl -e "my $string = 'Joe'; print $string;"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (syntax error at -e line 1, near "my =":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Execution of -e aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
有人能指出我错过的明显错误吗?谢谢.我通常在UNIX上执行此操作但使用后退滴答.作为包装而不是双引号.
试试这个,但我无法测试它
perl -e 'my $string = ''Joe''; print $string;'
Run Code Online (Sandbox Code Playgroud)
在powershell中$string是一个变量,在双引号变量中使用赋值的值进行扩展.单引号中的字面值.'用单引号来逃避加倍''
或尝试:
perl -e "my `$string = 'Joe'; print `$string;"
Run Code Online (Sandbox Code Playgroud)
`是powershell中的转义字符.