[Scottish] Script hates whitespace

Keith Wyse kwyse3436 at gmail.com
Fri Jul 19 10:57:55 UTC 2013


Thanks Claudio, that's working great.
I'll have to read up some more on that and add it to my toolkit.

Thanks for your help!
Keith


On 19 July 2013 11:36, Claudio Calvelli <scotlug at intercal.org.uk> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/scottish/attachments/20130719/7fffeafa/attachment.html>


More information about the Scottish mailing list