summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpdfmerge10
1 files changed, 9 insertions, 1 deletions
diff --git a/pdfmerge b/pdfmerge
index b7dd387..26db6f1 100755
--- a/pdfmerge
+++ b/pdfmerge
@@ -3,9 +3,17 @@
args=$(($# - 1))
+infiles=(${@:1:args})
+outfile=${!#}
+
if [[ $# = 0 ]] || [[ $args = 0 ]]; then
echo "usage: ${0##*/} input.pdf [input2.pdf ..] output.pdf"
exit 0
fi
-gs -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${!#} -sDEVICE=pdfwrite "${@:1:$args}"
+if [[ -e $outfile ]]; then
+ printf "Error: Output file '%s' already exists!\n" "$outfile" >&2
+ exit 1
+fi
+
+gs -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$outfile" -sDEVICE=pdfwrite "${infiles[@]}"