diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 8821751a051cf22b3aa1f5093deb79817237b814..a00681ef7f0274de6d188bd66d01cc1d21bb038e 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -207,7 +207,7 @@ function _spack_pathadd {
 
 # Export spack function so it is available in subshells (only works with bash)
 if [ -n "${BASH_VERSION:-}" ]; then
-	export -f spack
+    export -f spack
 fi
 
 #
@@ -224,14 +224,6 @@ if [ -z "$_sp_source_file" ]; then
     fi
 fi
 
-#
-# Find root directory and add bin to path.
-#
-_sp_share_dir=$(cd "$(dirname $_sp_source_file)" && pwd)
-_sp_prefix=$(cd "$(dirname $(dirname $_sp_share_dir))" && pwd)
-_spack_pathadd PATH       "${_sp_prefix%/}/bin"
-export SPACK_ROOT=${_sp_prefix}
-
 #
 # Determine which shell is being used
 #
@@ -251,6 +243,17 @@ function _spack_determine_shell() {
 }
 export SPACK_SHELL=$(_spack_determine_shell)
 
+#
+# Find root directory and add bin to path.
+#
+# We send cd output to /dev/null to avoid because a lot of users set up
+# their shell so that cd prints things out to the tty.
+#
+_sp_share_dir="$(cd "$(dirname $_sp_source_file)" > /dev/null && pwd)"
+_sp_prefix="$(cd "$(dirname $(dirname $_sp_share_dir))" > /dev/null && pwd)"
+_spack_pathadd PATH "${_sp_prefix%/}/bin"
+export SPACK_ROOT="${_sp_prefix}"
+
 #
 # Check whether a function of the given name is defined
 #