Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ps2pdf correctly in a script?

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
like image 486
Ben Fossen Avatar asked Apr 18 '26 10:04

Ben Fossen


2 Answers

Just give it the PDF output filename explicitly:

find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' | xargs -l -i  ps2pdf '{}.ps' '{}.pdf'
like image 138
nneonneo Avatar answered Apr 20 '26 02:04

nneonneo


Here is one solution:

find $STARTDIR -name '*.ps' -print |
while read filename
do
  ps2pdf ${filename} ${filename%.ps}.pdf
done
like image 41
Robᵩ Avatar answered Apr 20 '26 01:04

Robᵩ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!