From e676fde9909946fc0078ec921936eb079c24fd8d Mon Sep 17 00:00:00 2001 From: native-api Date: Wed, 18 May 2022 16:15:05 +0300 Subject: [PATCH] Fix endless loop in `pyenv init -` under SSH in some shell setups (#2374) --- libexec/pyenv-init | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libexec/pyenv-init b/libexec/pyenv-init index 6d6cbf9a..f3b0f38b 100755 --- a/libexec/pyenv-init +++ b/libexec/pyenv-init @@ -148,7 +148,14 @@ function print_path() { echo 'set -gx PATH '\'"${PYENV_ROOT}/shims"\'' $PATH' ;; * ) - echo 'PATH="$(bash -ec '\''IFS=:; paths=($PATH); for i in ${!paths[@]}; do if [[ ${paths[i]} == "'\'"${PYENV_ROOT}/shims"\''" ]]; then unset '\'\\\'\''paths[i]'\'\\\'\''; fi; done; echo "${paths[*]}"'\'')"' + # Some distros (notably Debian-based) set Bash's SSH_SOURCE_BASHRC compilation option + # that makes it source `bashrc` under SSH even when not interactive. + # This is inhibited by a guard in Debian's stock `bashrc` but some people remove it + # in order to get proper environment for noninteractive remote commands + # (SSH provides /etc/ssh/sshrc and ~/.ssh/rc for that but no-one seems to use them for some reason). + # This has caused an infinite `bashrc` execution loop for those people in the below nested Bash invocation (#2367). + # --norc negates this behavior of such a customized Bash. + echo 'PATH="$(bash --norc -ec '\''IFS=:; paths=($PATH); for i in ${!paths[@]}; do if [[ ${paths[i]} == "'\'"${PYENV_ROOT}/shims"\''" ]]; then unset '\'\\\'\''paths[i]'\'\\\'\''; fi; done; echo "${paths[*]}"'\'')"' echo 'export PATH="'"${PYENV_ROOT}"'/shims:${PATH}"' ;; esac