Note that because shell scripts are *wonderful*, you cannot rely on $0
being the path to the calibre-uninstall script (programs are freely
permitted to define their own argv0), and in some cases it won't be
deleted properly (although everything else will be).
e.g. one way to *accidentally* trigger this is with
bash calibre-uninstall
$0 will be 'calibre-uninstall', bash detects the program on $PATH, but
it's not relative to ./ and you cannot trace it back to the original
source file, so the uninstaller doesn't get detected as existing.
The bash-specific equivalent of `__file__` is ${BASH_SOURCE[0]} which
has nothing to do with argv0 and does, in fact, explicitly refer to the
filename of the file which is currently being parsed, but /bin/sh has
*no* way of detecting this. None. Period. It cannot be done.
(In order to break BASH_SOURCE you need to do something like:
`cat /usr/bin/calibre-uninstall | bash`, which would break python
`__file__` too.)
It's *probably* okay to say "if you find yourself invoking the
calibre-uninstall program in some way that lies about $0, you deserve to
not have it uninstalled with the rest".
Just thought you might be interested in adding to the list of
frustrations to bill Canonical for. :)
Note that because shell scripts are *wonderful*, you cannot rely on $0
being the path to the calibre-uninstall script (programs are freely
permitted to define their own argv0), and in some cases it won't be
deleted properly (although everything else will be).
e.g. one way to *accidentally* trigger this is with
bash calibre-uninstall
$0 will be 'calibre- uninstall' , bash detects the program on $PATH, but
it's not relative to ./ and you cannot trace it back to the original
source file, so the uninstaller doesn't get detected as existing.
The bash-specific equivalent of `__file__` is ${BASH_SOURCE[0]} which
has nothing to do with argv0 and does, in fact, explicitly refer to the
filename of the file which is currently being parsed, but /bin/sh has
*no* way of detecting this. None. Period. It cannot be done.
(In order to break BASH_SOURCE you need to do something like: calibre- uninstall | bash`, which would break python
`cat /usr/bin/
`__file__` too.)
It's *probably* okay to say "if you find yourself invoking the
calibre-uninstall program in some way that lies about $0, you deserve to
not have it uninstalled with the rest".
Just thought you might be interested in adding to the list of
frustrations to bill Canonical for. :)