[Scottish] [edlug] Script hates whitespace

Faye Gibbins wibble at morpheux.org
Fri Jul 19 11:33:37 UTC 2013

Have you tried quoting around the "{}"? viz:

$ sh -c 'echo "`basename foo .pdf`.epub"'
$ sh -c 'echo "`basename foo bar .pdf`.epub"'
basename: extra operand `.pdf'
Try `basename --help' for more information.
$ sh -c 'echo "`basename \"foo bar\" .pdf`.epub"'
foo bar.epub


On Fri, 19 Jul 2013, Keith Wyse wrote:

> 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"' \;
> This works on a file and path which doesn't have whitespace, but won't if there are any whitespaces.
> I've tried putting different types of quotes around the {} parts and using the -print0 option to find, but these didn't do
> the trick. I'm no expert so at a loss.
> Can someone suggest a way to alter the script to accept whitespace?
> I have other similar scripts to convert from .lit .txt. and .mobi to .epub and .mobi by changing the options above.
> Interestingly tho, ebook-convert works fine if I give it the .pdf with whitespace in escaped format on the command line.
> Many thanks
> Keith
> Scottish Borders

More information about the Scottish mailing list