Search code examples
bashshellsh

How to use xargs to replace 2 arguments


I would like to write a script to convert svg files in a directory to png using svgexport cli

svgexport input.svg input.jpg

How can I use find and xargs -I {} to find and print out the svg files using the following:

find . -iname -0 "*.svg" | xargs -I {} svgexport {} ???

How can I fill-in the second argument by using the first argument and replacing .svg with .jpg?


Solution

  • I think it's best to do this with a while loop:

    find . -iname "*.svg" -print0 |
        while IFS= read -r -d '' file; do
            svgexport "$file" "${file%.svg}.jpg"
        done