From 600f3c11042a77c44aff4372aba59d56cdc76955 Mon Sep 17 00:00:00 2001
From: Todd Gamblin <tgamblin@llnl.gov>
Date: Thu, 30 May 2019 01:41:55 -0500
Subject: [PATCH] setup-env.sh: send cd output to /dev/null when it affects
 Spack

- We've seen this a few times now where users have set up `cd` to echo
  the new directory, and it screws up `setup-env.sh`

- In the past we've said this is user error.

- Here, we just fix it by sending `cd` output to /dev/null where needed.
  - this works in bash, zsh, and dash
---
 share/spack/setup-env.sh | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 8821751a05..a00681ef7f 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
 #
-- 
GitLab