Stalin Kay Stalin Kay - 2 months ago 15
Bash Question

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?

Answer

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"
    do