問題描述
我被 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模板網!