diff --git a/contrib/pg_upgrade/test.sh b/contrib/pg_upgrade/test.sh
index d44c599a8ee9618f7de571046989bf903373eb1c..905729028fa8e3286a02cc8e8f4bca98c4ca734b 100644
--- a/contrib/pg_upgrade/test.sh
+++ b/contrib/pg_upgrade/test.sh
@@ -60,7 +60,8 @@ esac
 POSTMASTER_OPTS="-F -c listen_addresses=$LISTEN_ADDRESSES -k \"$PGHOST\""
 export PGHOST
 
-temp_root=$PWD/tmp_check
+# don't rely on $PWD here, as old shells don't set it
+temp_root=`pwd`/tmp_check
 
 if [ "$1" = '--install' ]; then
 	temp_install=$temp_root/install
@@ -117,7 +118,7 @@ PGREQUIRESSL="";      unset PGREQUIRESSL
 PGCONNECT_TIMEOUT=""; unset PGCONNECT_TIMEOUT
 PGHOSTADDR="";        unset PGHOSTADDR
 
-logdir=$PWD/log
+logdir=`pwd`/log
 rm -rf "$logdir"
 mkdir "$logdir"