diff options
author | ache <ache@ache.one> | 2017-04-03 07:59:59 +0200 |
---|---|---|
committer | ache <ache@ache.one> | 2017-04-18 04:57:06 +0200 |
commit | 04051c56d4bd91e69b601d5717023212aa9edbd1 (patch) | |
tree | f8abde4e6c3a79d1f42f992374bf3837fa73ca58 | |
parent | Add a readme (diff) |
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.
-rwxr-xr-x | img2pdf.sh | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -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; |