diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 49849b371bc5d992689c7bb42961cfa0bb757bd6..eef6be2a5c6a45ccefe6b9a1865fa910ddd72a42 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -42,20 +42,18 @@ case $testhost in
 		# script; the outcome mimics pg_regress.c:make_temp_sockdir().
 		PGHOST=$PG_REGRESS_SOCK_DIR
 		if [ "x$PGHOST" = x ]; then
-			{
-				dir=`(umask 077 &&
-					  mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null` &&
-				[ -d "$dir" ]
-			} ||
-			{
+			set +e
+			dir=`(umask 077 &&
+				  mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null`
+			if [ ! -d "$dir" ]; then
 				dir=/tmp/pg_upgrade_check-$$-$RANDOM
 				(umask 077 && mkdir "$dir")
-			} ||
-			{
-				echo "could not create socket temporary directory in \"/tmp\""
-				exit 1
-			}
-
+				if [ ! -d "$dir" ]; then
+					echo "could not create socket temporary directory in \"/tmp\""
+					exit 1
+				fi
+			fi
+			set -e
 			PGHOST=$dir
 			trap 'rm -rf "$PGHOST"' 0
 			trap 'exit 3' 1 2 13 15