Re: Script hates whitespace

Claudio Calvelli <[email protected]>
Newsgroups gmane.user-groups.linux.scottish
Message-ID <[email protected]>
Keith Wyse writes:
> Hi all;
> I'm having some trouble with a little script I'm writing - it hates
> whitespace.
> I have a bunch of books in .pdf format, but I can read them better in .epub
> because of page resizing and font resizing. I wanted to use Calibre's
> command line ebook-convert to modify them.
> So the main line of the script is;
> 
> find . -name "*.pdf" -execdir sh -c 'ebook-convert {} "`basename {}
> .pdf`.epub"' \;

That results in the command being expanded several times by various shells,
not a good combination.  You could try:

find . -name '*.pdf' -print0 | \
while read -r -d '' f; do pushd "`dirname "$f"`"; n="`basename "$f"`"; \
ebook-convert "$n" "${n%.pdf}.epub"; popd; done

which is naturally self-explanatory but in case it isn't, you have
your shell reading each name (NUL-delimited, using "-print0" to "find"
and "-d ''" to the shell's "read" builtin) and then use the shell's own
string manipulation to remove the ".pdf".  I don't have ebook-convert,
but if I replace it with "echo" I get the list I would expect.

Or you could use something other than a shell one-liner :-)

HTH
C
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.