diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 943db726120b06998cc11b8d74fd19d242b2681b..24ab3dae6f406635fa89631d00665ea932bd6598 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -167,6 +167,11 @@ function _spack_pathadd {
     fi
 }
 
+# Export spack function so it is available in subshells (only works with bash)
+if [ -n "${BASH_VERSION:-}" ]; then
+	export -f spack
+fi
+
 #
 # Figure out where this file is.  Below code needs to be portable to
 # bash and zsh.