diff --git a/drush b/drush
index e1f1f50..d6fd295 100755
--- a/drush
+++ b/drush
@@ -6,8 +6,8 @@
 #
 
 # Get the absolute path of this executable
-ORIGDIR=$(pwd)
-SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
+SELF_DIRNAME="`dirname -- "$0"`"
+SELF_PATH="`cd -P -- "$SELF_DIRNAME" && pwd -P`/`basename -- "$0"`"
 
 # Resolve symlinks - this is the equivalent of "readlink -f", but also works with non-standard OS X readlink.
 while [ -h "$SELF_PATH" ]; do
@@ -15,17 +15,17 @@ while [ -h "$SELF_PATH" ]; do
     # 2) cd to the directory of where the symlink points
     # 3) Get the pwd
     # 4) Append the basename
-    DIR=$(dirname -- "$SELF_PATH")
-    SYM=$(readlink $SELF_PATH)
-    SELF_PATH=$(cd "$DIR" && cd "$(dirname -- "$SYM")" && pwd)/$(basename -- "$SYM")
+    DIR="`dirname -- "$SELF_PATH"`"
+    SYM="`readlink $SELF_PATH`"
+    SYM_DIRNAME="`dirname -- "$SYM"`"
+    SELF_PATH="`cd "$DIR" && cd "$SYM_DIRNAME" && pwd`/`basename -- "$SYM"`"
 done
-cd "$ORIGDIR"
 
 # Build the path to drush.php.
-SCRIPT_PATH=$(dirname "$SELF_PATH")/drush.php
-case $(uname -a) in
+SCRIPT_PATH="`dirname "$SELF_PATH"`/drush.php"
+case "`uname -a`" in
   CYGWIN*)
-    SCRIPT_PATH=$(cygpath -w -a -- "$SCRIPT_PATH") ;;
+    SCRIPT_PATH="`cygpath -w -a -- "$SCRIPT_PATH"`" ;;
 esac
 
 # If not exported, try to determine and export the number of columns.
@@ -36,7 +36,7 @@ esac
 # terminal and prints out the default value (80).
 if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != dumb ] && [ ! -z "`which tput`" ] ; then
   # Note to cygwin users: install the ncurses package to get tput command.
-  if COLUMNS=$(tput cols); then
+  if COLUMNS=`tput cols`; then
     export COLUMNS
   fi
 fi
@@ -47,23 +47,24 @@ if [ ! -z "$DRUSH_PHP" ] ; then
 else
   # Default to using the php that we find on the PATH.
   # Note that we need the full path to php here for Dreamhost, which behaves oddly.  See http://drupal.org/node/662926
-  php=`which php`
+  php="`which php`"
 
   # We check for a command line (cli) version of php, and if found use that.
-  which php-cli >/dev/null 2>&1
-  if [ "$?" = 0 ] ; then
-    php=`which php-cli`
+  PHPCLI="`which php-cli 2>/dev/null`"
+  if [ ! -z "$PHPCLI" ] ; then
+    php="PHPCLI"
   fi
 
   # On MSYSGIT, we need to use "php", not the full path to php
-  if [ ! -z "$MSYSTEM" ] && [ "x${MSYSTEM:0:5}" = "xMINGW" ] ; then
+  # See http://drupal.org/node/1659014 for an explanation of the comparison op.
+  if [ ! -z "$MSYSTEM" ] && [ "x${MSYSTEM}" != "x${MSYSTEM#MINGW}" ] ; then
     php="php"
   fi
 fi
 
 # Check to see if the user has provided a php.ini file or drush.ini file in any conf dir
 # Last found wins, so search in reverse priority order
-for conf_dir in $(dirname "$SELF_PATH") /etc/drush $HOME/.drush ; do
+for conf_dir in "`dirname "$SELF_PATH"`" /etc/drush $HOME/.drush ; do
   if [ -f $conf_dir/php.ini ] ; then
     drush_php_ini=$conf_dir/php.ini
   fi
