Perl:带有引号和反引号的系统命令 [英] Perl: System command with both quotes and backticks

查看:176
本文介绍了Perl:带有引号和反引号的系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Perl中发送OSX命令.但是我不知所措,因为该命令同时包含引号和反引号,而且我还无法弄清楚如何对两个字符进行转义并获得功能性的系统命令.

I am trying to send an OSX command from within Perl. However I am at a loss because the command contains both quotes and backticks, and I have not been able to figure out how to escape both characters and get a functional system command.

这是终端命令:
/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'

Here is the terminal command:
/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'

感谢您的见解!

推荐答案

您可以使用q

You can use q quote-like operator, which works like ordinary single quote (or qq, equivalent to double qoute). This gives you advantage of using delimieters of choice.

my $cmd = q{/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'};
system $cmd;

您还可以将列表传递给system,将外部程序的每个参数作为列表项.这样,您不必引用否则将由Shell解释的参数:

You can also pass list to system, witch each argument to external program as list item. This way you do not have to quote arguments that would be otherwise interpreted by shell:

system('/usr/bin/osascript', '-e', 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down');

这篇关于Perl:带有引号和反引号的系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆