Subject: bash interaction with ssh causes it to read .bashrc despite being non-interactive Package: bash Version: 5.0-4 Severity: normal
When SSHing into a machine using bash as the shell, launching asynchronous sub-shells in that shell causes the sub-shell to execute /etc/bash.bashrc and .bashrc. Reproducer: 1. Put the line "echo Hello from .bashrc" at the very beginning of the .bashrc on <somehost> 2. ssh into <somehost> 3. Execute the following command: > bash -c 'echo SHLVL=$SHLVL ; echo \$-=$-' & wait [1] 27048 Hello from .bashrc SHLVL=1 $-=hBc [1]+ Done bash -c 'echo SHLVL=$SHLVL ; echo \$-=$-' Note that there is output from .bashrc, despite $- reporting that the shell is not interactive. Also note that SHLVL stays at one, this seems to be the cause for this behaviour. Executing the same command without '&' works as expected: > bash -c 'echo SHLVL=$SHLVL ; echo \$-=$-' SHLVL=2 $-=hBc Here SHLVL is correctly increased to 2, and no output from .bashrc is seen. Unsetting the environment variable SSH_CLIENT causes yet another variation in behaviour: > bash -c 'echo SHLVL=$SHLVL ; echo \$-=$-' & wait [1] 29257 SHLVL=1 $-=hBc [1]+ Done bash -c 'echo SHLVL=$SHLVL ; echo \$-=$-' Here SHLVL incorrectly stays at 1, but no output from .bashrc is seen. The problem is most likely related to the following change (see file CHANGES) between version bash-4.4-release and bash-5.0-alpha. [...] f. Fixed a bug that caused SHLVL to be incremented one too many times when creating subshells. [...] In shell.c, function run_startup_files() is the code responsible for executing .bashrc in certain circumstances. If the shell finds the environment variable SSH_CLIENT to be defined and SHLVL is less than 2, .bashrc is executed. My guess is that the fix mentioned above has the (probably unintended) consequence that SHLVL is no longer increased for asynchronous sub-shells and therefore the code executing .bashrc is triggered incorrectly. -- System Information: Debian Release: 10.1 APT prefers stable-updates APT policy: (800, 'stable-updates'), (700, 'stable'), (500, 'stable-debug') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.19.0-6-amd64 (SMP w/8 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages bash depends on: ii base-files 10.3+deb10u1 ii debianutils 4.8.6.1 ii libc6 2.28-10 ii libtinfo6 6.1+20181013-2+deb10u1 Versions of packages bash recommends: ii bash-completion 1:2.8-6 Versions of packages bash suggests: pn bash-doc <none> -- Configuration Files: /etc/bash.bashrc changed [not included] -- no debconf information

