I have a script below and I am having problems. I have several folders with PostScript file in them I want to batch convert to PDFs. I have done very little scripting in linux before but I think this is close. It is not quite working how I want it though. Any suggesting? or notice a mistake I made? I want the files to stay in the same location after they have been converted. Currently this converts the files but they get all put together in one folder.
I call the script like this: ./all.ps.to.pdf "/directory/to/process"
#!/bin/sh
STARTDIR=$1
if [ ! -d "$STARTDIR" ]; then
echo No starting directory $STARTDIR
exit 1
fi
find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' |
xargs -l -i ps2pdf \{}.ps
Just give it the PDF output filename explicitly:
find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' | xargs -l -i ps2pdf '{}.ps' '{}.pdf'
Here is one solution:
find $STARTDIR -name '*.ps' -print |
while read filename
do
ps2pdf ${filename} ${filename%.ps}.pdf
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With