macos shell脚本中的Automator变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4663982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automator Variable in shell script
提问by switz
Is it possible to pass an Automator variable into a shell script?
是否可以将 Automator 变量传递给 shell 脚本?
采纳答案by mklement0
To complement @Ned Deily's answer:
(Written as of OS X 10.9.2, still current as of OSX 10.10)
(从 OS X 10.9.2 开始编写,从 OSX 10.10 开始仍然有效)
It is often notnecessary to create and use explicitvariablesin Automator (using the Set Value of Variable
and Get Value of Variable
actions).
它往往不是必需的创建和使用明确的变量中的Automator(使用Set Value of Variable
和Get Value of Variable
操作)。
The previous action's output is automatically passed to a Run Shell Script
action.
上一个动作的输出会自动传递给一个Run Shell Script
动作。
By default, the data is passed via stdin, however.
但是,默认情况下,数据通过stdin传递。
If you want it passed as arguments($1
, $2
, ... - also accessible as an array via $@
) instead, select as arguments
from the Pass input:
list on the right, as illustrated here:
如果您希望将其作为参数传递( $1
, $2
, ... - 也可通过数组访问$@
),请as arguments
从Pass input:
右侧的列表中进行选择,如下所示:
In this example, the selected Finder
items are passed as POSIX-style pathsto the shell script.
在此示例中,所选Finder
项目作为POSIX 样式的路径传递给 shell 脚本。
That said, having a shell script process the data via stdin(using read -r
in a loop) works, too:
也就是说,让 shell 脚本通过stdin(read -r
在循环中使用)处理数据也有效: