I'm trying to learn script and found this post Extract TOC from epub file, which give me part of solution that I need, but when I tested it, got an error error: Extra content at the end of the document
.
A little bit of background: I have 2 epub files: 1.epub
and 2.epub
. I tested each one separately, it worked fine (got the TOC from each epub), but when I tried to test both files using do
, got the above error.
I'm learning scripts, not sure if I made a mistake somewhere. Anyone can point what's my mistake?
ps: my script
#! /usr/bin/bash
EPUB_LIST="1.epub 2.epub"
for f in "$EPUB_LIST"
do
echo "$f:"
unzip -p "$f" OEBPS/toc.ncx |
xml2 |
sed -n -e 's:^/ncx/navMap/navPoint/navLabel/text=: :p'
echo
done
ls
command to retrieve it automatically, the solution I used isEPUB_LIST=$(ls my*.epub)
, when I tried to run it, got an error:error: Extra content at the end of the document
. my guess isls
is putting EOL at the end of each file name, is there an easy way to remove it? Thanks for your help – michaelbr Aug 28 '22 at 08:15ls
(and what to do instead)? for reasons why.EPUB_LIST=(my*.epub)
works better, and without the risks and problems of parsing the output of ls. Or you could usemapfile -d '' -t EPUB_LIST < <(find . -type f -name '*.epub' -print0)
- this version is especially useful if you have a directory tree of .epub files to process...and find has a lot of options for refining exactly which files get selected. – cas Aug 28 '22 at 08:24error: Extra content at the end of the document
message is coming fromxml2
- the most probable cause is that you tried to pipe a non-existent or empty file (i.e. the .epub didn't contain a file calledOEBPS/toc.ncx
). You'll want to examine the books where that happens and see if they have another TOC file (one of the other answers to the linked question has some solutions to that). There are several versions of epub files, and the TOC file isn't always named toc.ncx. – cas Aug 28 '22 at 08:27(my*.epub)
(learning something new every day). And thanks for the tips about TOC, will take another look at my epub files. – michaelbr Aug 28 '22 at 08:43