2

Code

#!/bin/sh
# http://tex.stackexchange.com/a/20886/13173
# http://unix.stackexchange.com/a/280830/16920
# $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $
# Convert PDF to encapsulated PostScript.
# usage:
# pdf2eps <page number> <pdf file without ext>

[ $# -lt 2 ] || echo "At least 2 arguments are needed" && exit 1

pdfcrop "$2.pdf"
pdftops -f "$1" -l "$1" -eps "$2-crop.pdf"
rm  "$2-crop.pdf"
mv  "$2-crop.eps" "$2.eps"

Run it as

pdf2eps 1 ./01-02-2002-01-02-03.pdf

Output

At least 2 arguments are needed

and no output file.


Why you cannot run here the command on 01-02.pdf?

6
[ $# -lt 2 ] || echo "At least 2 arguments are needed" && exit 1

checks whether the number of arguments is strictly less than 2, and if it's not, outputs "At least 2 arguments are needed". You need to replace the || with &&:

[ $# -lt 2 ] && echo "At least 2 arguments are needed" && exit 1

I think the example you linked to in Safe way to install .sh script in /usr/local/bin? is actually easier to understand (and -ne is better suited since having more than 2 arguments is probably an error):

if [ $# -ne 2 ]; then
    echo "Exactly 2 filenames are needed"
    exit 1
fi

Note too that you're not supposed to specify the extension, so you should run the command as

pdf2eps 1 ./01-02-2002-01-02-03
  • My bad. The OP took the [ $# -lt 2 ] || echo from a comment of mine, and I had mistakenly used || instead of &&. I've now edited the comment as well to avoid future confusion. – terdon May 4 '16 at 7:57
  • @terdon that's when it's handy to be a moderator ;-). – Stephen Kitt May 4 '16 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.