开发者

Passing shell result to another shell command?

开发者 https://www.devze.com 2023-04-06 05:21 出处:网络
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

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 a开发者_C百科ction:

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!


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
0

精彩评论

暂无评论...
验证码 换一张
取 消