To count open epubs I used this:
# - determine how many epubs are open -
NUMBER_OF_OPEN_EPUBS=0
while read -r LINE ; do
if [ "$(echo $LINE | rev | cut -c1-5 | rev)" = ".epub" ]; then
NUMBER_OF_OPEN_EPUBS="$(($NUMBER_OF_OPEN_EPUBS+1))"
fi
done < <(lsof | grep "\.epub")
# --- end determine how many epubs are open ---
and it always worked. But I wanted to extend it to fb2 files (similar to epubs) as well so I got an fb2 for testing and couldn't make it work. To illustrate the underlying problem in it's simplest form:
With 2 files, /test.epub
& /test.fb2
open in fbreader
in seperate windows, in bash, in lxterminal, under Ubuntu 14.04 LTS and plain Openbox
:
me@nu:~$ lsof | grep "\.fb2" | tr -s " "
me@nu:~$ lsof | grep "\.epub" | tr -s " "
fbreader 28982 me 12r REG 8,5 346340 8375 /test.epub
me@nu:~$
Why doesn't lsof
see the fb2
? In practical terms, I suppose I could use ps
, which exhibits no prejudice against fb2
files (and incidentally proves grep
isn't to blame) instead, but why does lsof
snub fb2
files?
================== P.S. I edited this to put it in proper context here, even though, thanks to Mr.Hyde, it is solved already. The question as stated reflects an implied and unexamined assumption which turns out to be false. See answer.