Re: RFD: Essential packages, /, and /usr
> I can. I just want to know if the command is available for my script to
> use; I don't care about the latest flamewar that moved it in or out of
> /usr or */sbin.
You are searching for a particular word, and that word may represent
a binary/script, a shell function, a shell alias, a shell builtin.
There may be many of the aforementioned things with the same name.
No mechanism exists to determine whether or not these things perform
similar actions or have similar interfaces.
Let's say that I want to run deathrampage in my postinst. deathrampage
is a binary in a package of the same name, and this is the deathrampage
that I wish to have executed. There are many ways for me to check for it:
(A) deathrampage || echo uh-oh, continuing without it
Advantages: portable
Disadvantages: requires running the program in question
(B) test -x /usr/sbin/deathrampage && /usr/sbin/deathrampage
Advantages: portable, will not execute the wrong deathrampage unless
someone has placed an impostor in /usr/sbin
Disadvantages: will fail silently if deathrampage is moved to /usr/bin
(C) multiple tests, or loop of tests
Advantages: portable, will handle multiple finite locations
Disadvantages: will fail silently if deathrampage is moved beyond the
finite list of locations
(D) command -v deathrampage 2>/dev/null && deathrampage
OR type deathrampage 2>/dev/null && deathrampage
Advantages: will find and execute deathrampage anywhere
Disadvantages: will find and execute deathrampage anywhere, no matter if
it is an alias to 'rm -rf /', a shell function that initiates
immediate reboot, or some other bizarre and unexpected thing. Not
POSIX-compliant.
(E) which deathrampage 2>/dev/null && command deathrampage
Advantages: will find and execute deathrampage on the command search path.
Disadvantages: not standardized at all. builtin which's will not
likely have the same interface.
(F) /usr/bin/which deathrampage 2>/dev/null && command deathrampage
Advantages: will find and execute deathrampage on the command search path.
Disadvantages: requires faith in /usr/bin/which not moving or changing
(G) dpkg -S deathrampage && some other stuff
Advantages: will only find deathrampages tracked by the Debian packaging
system.
Disadvantages: slow and cumbersome
(H) #!/bin/specific shell, and use known whence, which, type commands
Advantages: no portability problems, and you might get exactly what you
want
Disadvantages: annoying to users everywhere
(I) invent a Debian-specific solution to this problem
Advantages: less confusion
Disadvantages: requires cognition, and people seem to feel differently
about whether or not they want random shell aliases, functions, and
binaries in /usr/local being executed by package scripts.
--
To UNSUBSCRIBE, email to debian-policy-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: