0

只是在这里学习 Automator,但我正在尝试对文件 (blah.rtf->blah.mobi) 运行转换命令,我想获取生成的 .mobi 文件并以不同的方式在其上运行另一个 shell 命令行动。要么,或者有没有办法将它设置为第二个变量并在同一个动作中对其进行操作?

到目前为止,这是我的代码(使用 Calibre 命令行工具):

第一个动作:

for f in "$@"
do
    ebook-convert "$f" "$f".mobi
done    

我想传递那个 .mobi 文件来运行:

for f in "$@"
do
    mv "$f" $(echo "$f" | cut -d'.' -f1).mobi
done

有什么想法吗?谢谢!

4

1 回答 1

3

为了将转换后的文件传递给后续操作,第一个操作必须输出它们的路径:

for f in "$@"
do
    ebook-convert "$f" "$f".mobi
    echo "$f".mobi
done

但是您可以通过首先创建具有正确名称的文件来使其更简单(正如@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
于 2011-09-20T06:34:09.083 回答