Reputation: 1007
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
Upvotes: 3
Views: 2261
Reputation: 16619
for i `find $STARTDIR -name '*.ps'` ; do ps2pdf $i $i.ps.pdf ; done
Upvotes: 0
Reputation: 90253
notice a mistake I made?
Yessss, Sir.
Your find
command should be all in one line. Or, if you want to spread it over two lines, use \
as the line continuation sign (which must be the very last character on the first line without any blanks following it!).
That is...
either use
find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' | xargs -l -i ps2pdf \{}.ps
or use
find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' | \
xargs -l -i ps2pdf \{}.ps
or even use
find $STARTDIR -name '*.ps' -print \
| sed -e 's/.ps$//' \
| xargs -l -i ps2pdf \{}.ps
(whichever you think looks "nicer" to your Bash reading eyes...).
Upvotes: 1
Reputation: 168636
Here is one solution:
find $STARTDIR -name '*.ps' -print |
while read filename
do
ps2pdf ${filename} ${filename%.ps}.pdf
done
Upvotes: 2
Reputation: 179452
Just give it the PDF output filename explicitly:
find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' | xargs -l -i ps2pdf '{}.ps' '{}.pdf'
Upvotes: 2