简体   繁体   中英

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. 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM