[issue431] wm-ng on grml-medium 0.1

Frank Terbeck bts at bts.grml.org
Sat Feb 14 22:32:23 CET 2009


Frank Terbeck <ft at grml.org> added the comment:

Michael Prokop <bts at bts.grml.org>:
> * Frank Terbeck <bts at bts.grml.org> [20090214 21:59]:
> 
> > > if type -a "$PROG" 1>/dev/null 2>&1 ; then
> 
> > > => Is this really a bashism?
> 
> > 'type -a' is probably. I don't even know what it does.
> > So, bash it is.
> 
> Just using 'which $PROG" would fix this issue, right? :)

Well, I don't think 'which' is covered by SUSv3 either. I think
originally, that was a csh script. If you really want POSIX
conformance, you'd do a loop over the dirs in $PATH and check if the
program in question is there and executable. That could go into a
shell library and would actually be cleaner than the
which-and-forget-about-the-output approach.

Such a function would look like this:

[snip]
is_installed() {
    prog="$1"

    ret=1
    oifs="$IFS"
    IFS=:
    for dir in $PATH; do
        [ -x "${dir:-.}/$1" ] && ret=0
    done

    IFS="$oifs"
    return "$ret"
}
[snap]

'which' isn't a builtin in shells like posh, dash or even bash.
Those rely on /bin/which or similar. And of course, an additional
fork() screws performance. :-)

Regards, Frank

----------
assignedto: mika
messages: 1244, 1245, 1876, 1877, 1881, 1883, 1884, 1887
nosy: ft, maddi, mika
priority: bug
status: in-progress
title: wm-ng on grml-medium 0.1
topic: release-stopper

_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue431>
_____________________________________


More information about the Bugs-changes mailing list