Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems handling spaces in filenames

4 views
Skip to first unread message

Philipp Klaus Krause

unread,
Jan 26, 2019, 3:36:29 PM1/26/19
to
I rarely write bash scripts, so I am not surprised I ran into trouble
with spaces in filenames in one:

#!/bin/bash
for i in `seq $2 $3`; do
base=$1-$i
image=${base}.jpeg
pdflist="${pdflist} \"$base.pdf\""
tesseract "$image" "$base" -l deu pdf;
done
pdfjoin $pdflist && rm $pdflist
mv "$1"-"$3"-joined.pdf "$1".pdf

I wrote and use this script to convert JPEG images (names e.g.
test-1.jpeg, test-2-jpeg, etc) to searchable pdf (names test.pdf).
However, the

pdfjoin $pdflist

isn't working when $1 contains spaces. Apparently the quotes are
disappearing somewhere along the way.

Philipp

Joe Rosevear

unread,
Jun 15, 2019, 4:23:38 PM6/15/19
to
Maybe

pdfjoin "$pdflist" && rm "$pdflist"

-Joe

Stephane Chazelas

unread,
Oct 22, 2019, 5:15:10 PM10/22/19
to
2019-01-26 21:36:28 +0100, Philipp Klaus Krause:
[...]

Use an array variable to store more than one value.

#! /bin/bash -
pdflist=()
for ((i = $2; i <= $3; i++)) {
base=$1-$i
image=$base.jpeg
pdflist+=("$base.pdf")
tesseract "$image" "$base" -l deu pdf
}
pdfjoin "${pdflist[@]}" && rm "${pdflist[@]}"
mv "$1-$3-joined.pdf" "$1.pdf"


Note that it won't work properly if $1 starts with "-". The
way to address it would be to use "--" for all commands, but
unfortunately it won't work with pdfjoin which calls pdfjam,
itself a Bourne-shell script that breaks when file names start
with "-" even if you pass "--" to pdfjoin.

One way to address it would be to prefix relative paths with
"./".

case $1 in
(/*) prefix=$1;;
(*) prefix=./$1;;
esac

--
Stephane


0 new messages