将 shell 结果传递给另一个 shell 命令?

发布于 2024-12-05 10:44:26 字数 416 浏览 0 评论 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

有什么想法吗?谢谢!

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. 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):

First action:

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

I'd like to pass that .mobi file to run:

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

Any thoughts? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉鱼一梦 2024-12-12 10:44:26

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

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

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):

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文