home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Re: ps2pdf and xargs

J C Nash wrote:
I wanted to convert all the ps files in a directory, so
tried

ls *.ps | xargs ps2pdf

but got the "usage" msg from ps2pdf. Tried a few alternative
with no joy and finally wrote a perl script that does a nice
job (available on request). However, I'd like to know why
xargs doesn't work here.

Ps2pdf seems to only process one input file at a time; a second filename, if any, is taken as the output file. So you were lucky you had more than two files;

    ps2pdf x.ps y.ps

will happily overwrite y.ps.

Here are three ways to do what you wanted:

    ls *.ps | xargs --replace ps2pdf {}

    for f in *.ps; do
        ps2pdf "$f"
    done

    find . -maxdepth 1 -name '*.ps' -exec ps2pdf {} \;

By the way, if your original attempt had worked, then you could also have done just "ps2pdf *.ps".

references