I want to write a Bash script to convert every .pdf
file
in the current directory into a .png
file.
For example:
$ls .
a.pdf b.pdf
$./pdf2png.sh
Converting pdfs to pngs
a.pdf -> a.png
b.pdf -> b.png
This is my best attempt:
#!/bin/bash
convert -verbose -density 500 -resize '800' a.pdf a.png
convert -verbose -density 500 -resize '800' b.pdf b.png
find . -type f -name '*.pdf' -exec sh -c 'for f do convert -verbose -density 500 -resize 800 "$f" "${f%.pdf}.png"; done' find-sh {} +
See https://unix.stackexchange.com/a/321753/135943 for explanation and background. – Wildcard Jun 26 '17 at 22:01-printf
, so all you'd need for portability is to replace it with-exec printf '%s\0' {} +
. – terdon Jun 26 '17 at 22:21