aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-04-03 07:59:59 +0200
committerache <ache@ache.one>2017-04-18 04:57:06 +0200
commit04051c56d4bd91e69b601d5717023212aa9edbd1 (patch)
treef8abde4e6c3a79d1f42f992374bf3837fa73ca58
parentAdd 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-ximg2pdf.sh26
1 files 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;