summaryrefslogtreecommitdiffstats
path: root/pdfmerge
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-04-02 19:41:17 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-04-02 19:41:17 +0200
commit7c04038cb1c56a43d40df52213c7eb4be375279c (patch)
treeb9549f004d844ede41c9b7c5c70339803ee8ebb5 /pdfmerge
parent355f8c8457863352412c730ba634f431b23091b7 (diff)
downloadbin-7c04038cb1c56a43d40df52213c7eb4be375279c.tar.gz
bin-7c04038cb1c56a43d40df52213c7eb4be375279c.tar.xz
pdfmerge: Don't overwrite files
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'pdfmerge')
-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[@]}"