我被 Automator.app 在 Mac OS X Snow Leopard 中创建上下文服务的能力所吸引.我想创建一些键盘可访问的快捷方式来通过调用 shell 脚本来操作文本片段.但是,Automator 只建议使用 bash、Perl、Python 和 Ruby(以及其他)来实现这一点.但是,由于 PHP 也随 Mac OS 一起提供(老实说,它是我唯一完全掌握的脚本语言),我想知道为什么我不能运行 PHP shell 脚本.
I'm tempted by Automator.app's ability to create contextual services in Mac OS X Snow Leopard. I would like to create some keyboard accessible shortcuts to manipulate text snippets by calling a shell script. However, Automator only suggests bash, Perl, Python and Ruby (among others) to allow this. But, since PHP also ships with Mac OS (and, to be honest, it's the only scripting language I fully master), I wonder why I can't run a PHP shell script.
上面dbr的解决方案很好,但是我发现它对我不起作用,可能是由于后来更改了shell、php或OS版本(我使用的是 OS X 10.8).经过大量的挠头,我发现答案是引用heredoc标记.
dbr's solution above is excellent, but I found that it didn't work for me, perhaps due to a later change in the shell, php, or OS version (I'm using OS X 10.8). After a lot of head-scratching I found that the answer is to quote the heredoc marker.
一个有用的补充是使用适当的语法将参数传递给 php 脚本.将所有这些放在一起,我正在使用:
A useful addition is to use the appropriate syntax to pass the arguments through to the php script. Putting all that together, I'm using:
php -- "$@" <<'EOF'
<?php
print_r( $argv );
?>
EOF
这篇关于如何在 Mac OS X 上执行 PHP shell 脚本作为 Automator 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!