[英]Passing shell result to another shell command?
Just learning Automator here, but I'm trying to run a convert command on a file (blah.rtf->blah.mobi) and I'd like to take the resulting .mobi file and run another shell command on it in a different action. 只是在这里学习Automator,但我试图在文件(blah.rtf-> blah.mobi)上运行转换命令,我想获取生成的.mobi文件,并在另一个文件上运行另一个shell命令。行动。 Either that, or is there a way to set it as a second variable and act on it in the same action? 要么,或者有没有办法将其设置为第二个变量并以相同的动作对其进行操作?
Here's my code so far (using Calibre command-line tools): 到目前为止,这是我的代码(使用Calibre命令行工具):
First action: 第一步:
for f in "$@"
do
ebook-convert "$f" "$f".mobi
done
I'd like to pass that .mobi file to run: 我想传递该.mobi文件运行:
for f in "$@"
do
mv "$f" $(echo "$f" | cut -d'.' -f1).mobi
done
Any thoughts? 有什么想法吗? Thanks! 谢谢!
In order to pass the converted files to subsequent actions, the first action must output their paths: 为了将转换后的文件传递给后续操作,第一个操作必须输出其路径:
for f in "$@"
do
ebook-convert "$f" "$f".mobi
echo "$f".mobi
done
But you can make it much simpler by making the first action create the files with the correct names in the first place (as @tripleee suggested): 但您可以通过执行第一个操作首先创建具有正确名称的文件来简化操作(如@tripleee建议):
for f in "$@"
do
ebook-convert "$f" "${f%.*}".mobi
# echo "${f%.*}".mobi # optional -- uncomment if you need to pass the files on to subsequent actions
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.