[PATCH 1/2] wineinstall - Switch from 'which' to 'type' to fix detection of programs

Chris Morgan chmorgan at gmail.com
Fri Feb 24 18:30:25 CST 2017

Use of 'which' was resulting in programs like rpm and wine being found when they didn't exist.

'which' has different behavior on different systems. For example, on Fedora 25:

    $>which blah
    /usr/bin/which: no blah in (/usr/lib64/qt-3.3/bin...

Means that "if [ -x `which blah` ] will always be true as /usr/bin/which always exists.

'type' exits with 0 if the program is found, non-zero if not.

Tested under bash, ksh, and csh.

Signed-off-by: Chris Morgan <chmorgan at gmail.com>
 tools/wineinstall | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/wineinstall b/tools/wineinstall
index e8e22bf..bfd62e3 100755
--- a/tools/wineinstall
+++ b/tools/wineinstall
@@ -70,7 +70,7 @@ then
 # check whether RPM installed, and if it is, remove any old wine rpm.
-if [ -x `which rpm 2>/dev/null` ]; then
+if type rpm &>/dev/null; then
     if [ -n "`rpm -qi wine 2>/dev/null|grep "^Name"`" ]; then
       echo "Warning: Old Wine RPM install detected. Do you want to remove it first?"
       conf_yesno_answer "(yes/no) "
@@ -96,7 +96,7 @@ if [ -x `which rpm 2>/dev/null` ]; then
 # check whether wine binary still available
-if [ -x `which wine 2>/dev/null` ] && [ -n "`wine --version 2>/dev/null`" ]
+if type wine &>/dev/null && [ -n "`wine --version 2>/dev/null`" ]
     echo "Warning !! wine binary (still) found, which may indicate"
     echo "a (conflicting) previous installation."

More information about the wine-patches mailing list