From 3f3303be2f9d8a517f5752a17dc348bee09125f7 Mon Sep 17 00:00:00 2001 From: David Lukes Date: Sun, 23 Feb 2020 23:42:06 +0100 Subject: [PATCH] Nested shells should not be login (#5247) --- notebook/terminal/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/notebook/terminal/__init__.py b/notebook/terminal/__init__.py index ce07cf6047..2d216cc1e6 100644 --- a/notebook/terminal/__init__.py +++ b/notebook/terminal/__init__.py @@ -21,8 +21,13 @@ def initialize(nb_app): shell = nb_app.terminado_settings.get('shell_command', [os.environ.get('SHELL') or default_shell] ) - # Enable login mode - to automatically source the /etc/profile script - if os.name != 'nt': + # Enable login mode - to automatically source the /etc/profile + # script, but only for non-nested shells; for nested shells, it's + # superfluous and may even be harmful (e.g. on macOS, where login + # shells invoke /usr/libexec/path_helper to add entries from + # /etc/paths{,.d} to the PATH, reordering it in the process and + # potentially overriding virtualenvs and other PATH modifications) + if os.name != 'nt' and int(os.environ.get("SHLVL", 0)) < 1: shell.append('-l') terminal_manager = nb_app.web_app.settings['terminal_manager'] = TerminalManager( shell_command=shell,