fix 'which' program compatibility.

Test the capabilities of the one we find, rather than guessing
based on the system type
This commit is contained in:
simonb 2005-03-10 13:53:26 +00:00
parent aa0a9cd506
commit b7d3dc2fa3
2 changed files with 59 additions and 70 deletions

View file

@ -130,14 +130,10 @@ Common tips to use with $command:
EOF
}
# ugly code for solaris compat.
case `uname` in
Linux|*BSD)
find_it() {
which $1 > /dev/null 2>&1 && shift && $*
}
;;
*)
# some which's have a reliable return code, some don't
# Lets figure out which which we have.
if which this_program_does_not_exist-no_really-aA1zZ9 >/dev/null 2>/dev/null; then
# can't rely on return value
find_it() {
file=`which $1 2> /dev/null`
if [ -x "$file" ]; then
@ -150,8 +146,12 @@ case `uname` in
return 1
fi
}
;;
esac
else
# can rely on return value
find_it() {
which $1 > /dev/null 2>&1 && shift && $*
}
fi
message() {

View file

@ -123,20 +123,10 @@ fluxbox-generate_menu was brought to you by:
EOF
}
# ugly code for solaris compat.
UNAME=`uname`
# echo "UNAME=$UNAME"
case "$UNAME" in
Linux|*BSD)
find_it() {
which $1 > /dev/null 2>&1 && shift && $*
}
find_it_options() {
which $1 > /dev/null 2>&1
}
;;
*)
# some which's have a reliable return code, some don't
# Lets figure out which which we have.
if which this_program_does_not_exist-no_really-aA1zZ9 >/dev/null 2>/dev/null; then
# can't rely on return value
find_it() {
file=`which $1 2> /dev/null`
if [ -x "$file" ]; then
@ -159,23 +149,22 @@ case "$UNAME" in
fi
}
;;
esac
else
# can rely on return value
find_it() {
which $1 > /dev/null 2>&1 && shift && $*
}
find_it_options() {
which $1 > /dev/null 2>&1
}
fi
case "$UNAME" in
Linux)
replaceWithinString(){
#echo "replaceWithinString: $1, $2, $3" >&2
#echo ${1//$2/$3} # causes error in BSD even though not used
echo $1 | awk "{ gsub(/$2/, \"$3\"); print }"
}
;;
*BSD)
replaceWithinString(){
echo $1 | awk "{ gsub(/$2/, \"$3\"); print }"
}
;;
esac
convertIcon(){
if [ ! -f "$1" ] ; then