#!/bin/bash ext=$1 suffix=$2 out=$3 if [ -z "$suffix" ] ; then echo "Merge multiples images into a single pdf" echo "img2pdf (png,jpg,tiff,...) (suffix) [output]" echo "" echo "Ex :" echo "img2pdf jpg photo_book vacances_2017.pdf" exit fi if [ -z "$out" ] ; then out=$suffix.pdf fi echo "Prise en compte de " $(ls -v | egrep "^$suffix" | egrep "\.$ext\$") while : ; do read -p "Continue (y/n)?" choice case "$choice" in y|Y ) break;; n|N ) exit;; * ) echo "Invalid input";; esac done echo "$suffix" for img in $(ls -v | egrep "^$suffix" | egrep "\.$ext\$") ; do echo Traitement de "$img" img2pdf --output "${img//$ext/pdf}" "$img" done if [ -e "$out" ] ; then echo "Gestion backup" set -x rm "$out" set +x fi gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$out" `ls -v | egrep \.pdf$` for img in *."$ext" ; do rm "${img//$ext/pdf}" done