From 04051c56d4bd91e69b601d5717023212aa9edbd1 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 3 Apr 2017 07:59:59 +0200 Subject: Code refactoring New variables / cleaner than $1 and $2 Fix the problem of variable length of extention Default value to the output name pdf. Numerical order to process pdf convertion. --- img2pdf.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/img2pdf.sh b/img2pdf.sh index 502b218..cdf3f96 100755 --- a/img2pdf.sh +++ b/img2pdf.sh @@ -1,18 +1,30 @@ #!/bin/bash -if [ $# -ne 2 ] ; then +ext=$1 +out=$2 + +if [ -z "$ext" ] ; then echo "img2pdf (png,jpg,tiff,...) (output)" exit fi +if [ -z "$out" ] ; then + out=$(basename `pwd`).pdf +fi -for img in *."$1" ; do +for img in $( echo `ls -v | egrep \."$ext"$` ) ; do echo Traitement de "$img" - convert "$img" "${img:0:-4}.pdf" + convert "$img" "${img:0:-$(( 1 + ${#ext})) }.pdf" done; -rm "$2" -gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$2" `ls -v | grep .pdf$` +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 *."$1" ; do - rm "${img:0:-4}.pdf" +for img in *."$ext" ; do + rm "${img:0: $(( -1 + -${#ext} )) }.pdf" done; -- cgit v1.2.3