From 7760a197c555cc8fa6e72653dca0a53b0e950dff Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Sun, 15 Feb 2009 16:51:19 +0100 Subject: [PATCH] Add ist_installed(), thanks ft! --- usr_bin/grml-exec-wrapper | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/usr_bin/grml-exec-wrapper b/usr_bin/grml-exec-wrapper index a826be1..f20ffd4 100755 --- a/usr_bin/grml-exec-wrapper +++ b/usr_bin/grml-exec-wrapper @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Filename: grml-exec-wrapper # Purpose: simple but smart program execution wrapper # Authors: grml-team (grml.org), (c) Michael Prokop @@ -28,7 +28,24 @@ case $PROG in *sudo*) PROG="$2" ;; esac -if type -a "$PROG" 1>/dev/null 2>&1 ; then +is_installed() { + prog="$1" + [ -z "$prog" ] && return 1 + + ret=1 + oifs="$IFS" + IFS=: + for dir in $PATH; do + [ -z "$dir" ] && continue + [ -x "$dir/$prog" ] && ret=0 && break + done + + IFS="$oifs" + unset oifs + return "$ret" +} + +if is_installed "$PROG" 1>/dev/null 2>&1 ; then exec $@ else RC=1 -- 2.1.4