#!/bin/bash # merge multiple pdfs into one args=$(($# - 1)) infiles=(${@:1:args}) outfile=${!#} if [[ $# = 0 ]] || [[ $args = 0 ]]; then echo "usage: ${0##*/} input.pdf [input2.pdf ..] output.pdf" exit 0 fi 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[@]}"