From 7c04038cb1c56a43d40df52213c7eb4be375279c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 2 Apr 2016 19:41:17 +0200 Subject: pdfmerge: Don't overwrite files Signed-off-by: Florian Pritz --- pdfmerge | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'pdfmerge') 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[@]}" -- cgit v1.2.3-24-g4f1b