如何用SYSTEM运行带"的命令?

如何用SYSTEM运行带"的命令?

我想在PERL中调用PHP的命令行模式发送邮件,很不幸地这个命令中即含有双引号,也含有单引号。命令如下:
/usr/bin/php -r 'mail("aaa@aaa.com","subject","contact");'
这一行命令在SHELL下直接执行是没有问题的。现在想在PERL中用system()来调用。但会报错。
#!/usr/bin/perl
system("/usr/bin/php -r 'mail("aaa@aaa.com","subject","contact");'");

出错如下:
Bareword found where operator expected at ./a.sh line 2, near ""/usr/bin/php -r 'mail("aaa"
        (Missing operator before aaa?)
Array found where operator expected at ./a.sh line 2, at end of line
String found where operator expected at ./a.sh line 2, near "com",""
Bareword found where operator expected at ./a.sh line 2, near "","subject"
        (Missing operator before subject?)
String found where operator expected at ./a.sh line 2, near "subject",""
Bareword found where operator expected at ./a.sh line 2, near "","contact"
        (Missing operator before contact?)
String found where operator expected at ./a.sh line 2, near "contact");'""
syntax error at ./a.sh line 2, near ""/usr/bin/php -r 'mail("aaa"
Execution of ./a.sh aborted due to compilation errors.

我估计有可能是命令中的引号引起这个问题,查了PERL手册也没找到解决办法,望大家出手相助,谢谢!
1.当你用""作为分界的时候,其中的"要backslash,照你的写法,perl会在这个地方帮你断句

[Copy to clipboard] [ - ]
CODE:
/usr/bin/php -r 'mail(

2.“”和''是不同的,什么时候里面的变量会解释(interpolation),什么时候不会解释?
3.别忘了

[Copy to clipboard] [ - ]
CODE:
use strict;
use warnings;

@在perl中是有特殊含义的
我引用的这条命令中即有双引号也有单引号,system()还可以用其它的符号引用命令么?
单引号和双引号已经足够了,只是你要注意用backslash转义,假如定界符是"的话如果其中还有"要\",这个在shell里面也是这么做的吧?
至于你说的其他引用符号有没有,是有的

QUOTE:
Customary        Generic        Meaning        Interpolates
''        q//        Literal string        No
""        qq//        Literal string        Yes
``        qx//        Command execution        Yes
()        qw//        Word list        No
//        m//        Pattern match        Yes
s///        s///        Pattern substitution        Yes
y///        tr///        Character translation        No
""        qr//        Regular expression        Yes

see

[Copy to clipboard] [ - ]
CODE:
print qq ( "this is a test \n");
print "this is a test\n";

因为第一句的定界符是(),后一句的定界符是"",所以前一句的"不是特殊字符,运行的结果是有"的,后一句"的意义特殊
定界符可以随意,第一句也可以写成下面的形式,打印出的结果是一样的

[Copy to clipboard] [ - ]
CODE:
print qq @"this is a test\n"@;
print qq {"this is a test\n"};
print qq ["this is a test\n];

你甚至可以这样

[Copy to clipboard] [ - ]
CODE:
print qq p"this is a test\n"p;

下面的情况要注意转义,因为要打印的内容中含有定界符

[Copy to clipboard] [ - ]
CODE:
print qq e"this is a t\est\n"e;

多谢churchmice兄的详细讲解!在下也曾尝试过转义里面的双引号,看来是忘了将@也转义一下,我现在将双引号和@都转义后已经得到正确的运行结果了。