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: ./ "/directory/to/process"


if [ ! -d "$STARTDIR" ]; then
echo No starting directory $STARTDIR
exit 1

find $STARTDIR -name '*.ps' -print | sed -e 's/.ps$//' |
xargs -l -i  ps2pdf \{}.ps


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...).

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
  ps2pdf ${filename} ${}.pdf

Need Your Help

Slim PHP Framework causing 'Fail to open page'

php api safari slim

I have set up a REST API using the Slim PHP framework, which works perfectly when using requests i.e

render the view using razorengine mvc

html razor content-management-system razorengine

I am using RazorEngine to get the view and load it as html.but however my problem is I am reading html code from my database,and show it on my web page .but it gave me string result on my web page ...