Re: Script hates whitespace
Keith Wyse <[email protected]>
| Newsgroups | gmane.user-groups.linux.scottish |
|---|---|
| Message-ID | <CAPu+KpdAirxzG_iCcVMLRuOrKwV9hyFaF=_TwJXJ+bY=g9mz0g@mail.gmail.com> |
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 <[email protected]> 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 > > _______________________________________________ Scottish mailing list [email protected] https://mailman.lug.org.uk/mailman/listinfo/scottish