Unexpected sourcing of ~/.bashrc under ssh

2019-10-24 Thread Francis . Montagnac


Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security 
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions 
-fstack-protector-strong -grecord-gcc-switch\
es -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic 
-fasynchronous-unwind-tables -fstack-clash-protection \
-fcf-protection -Wno-parentheses -Wno-format-security
uname output: Linux nbrume 5.3.6-200.fc30.x86_64+debug #1 SMP Mon Oct 14 
12:47:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 5.0
Patch Level: 7
Release Status: release

Description:

  When logged on a machine with ssh, executing a simple command CMD1
  that spawn a "/bin/bash -c some other command" do not source
  ~/.bashrc: normal behaviour.

  When executing "CMD1 | CMD2", the ~/.bashrc is sourced: wrong  .

  I have tested that with perl and make as CMD1.

  This bug is not present in bash-4.2.48-2.fc14.1.x86_64

Repeat-By:

  Add for example in ~/.bashrc:

echo "Sourcing .bashrc, \$- = $-"

  connect to this machine with ssh, then execute:

$ perl -e 'exec "/bin/bash","-c","echo foo"'
foo
$ perl -e 'exec "/bin/bash","-c","echo foo"' | cat
Sourcing .bashrc, $- = hBc
foo
$ 

Turnaround:

  For make, defines: SHELL := /bin/bash --norc

  Unsetting the SSH_CLIENT variable works also.

-- 
Francis Montagnac



Re: Unexpected sourcing of ~/.bashrc under ssh

2019-10-24 Thread Greg Wooledge
On Thu, Oct 24, 2019 at 09:01:07AM +0200, francis.montag...@inria.fr wrote:
>   When logged on a machine with ssh, executing a simple command CMD1
>   that spawn a "/bin/bash -c some other command" do not source
>   ~/.bashrc: normal behaviour.
> 
>   When executing "CMD1 | CMD2", the ~/.bashrc is sourced: wrong  .

Bash can be built with a compile-time option that causes it to try to
detect when it's the non-interactive child of an ssh session, and source
the user's ~/.bashrc under those conditions.

Many Linux distributions enable this option, because they believe that
their users expect this behavior.