Package: base-files
Version: 6.0squeeze2
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Per bash manual: "When bash is invoked with the name sh, it tries to mimic 
the startup behavior of historical versions of sh as closely as possible, 
while conforming to the posix standard as well".

However, the current conditional code in /etc/profile does not address this
and results in sourcing /etc/bash.bashrc even when bash is invoked as /bin/sh
(to try it, just prepend a line 'echo "bash.bashrc"' in /etc/bash.bashrc and
then issue a `sh --login' command, after of course ensuring that the /bin/sh
symlink points to /bin/bash).

A patch is attached that tests for this case (etc_profile-bash_as_sh.patch). 

Note that since bash enters posix mode after reading the startup files the 
only way to check is to examine the value of $BASH. This btw may also mean 
that any code inside the startup files which uses `shopt -oq posix' checks 
(such as bash_completion) is probably broken. Note also that there is no need
to check for the `bash --posix --login' case, since then bash does not read 
any startup files and only honors ENV variable. 

I don't know if letting /etc/bash.bashrc to be sourced even on the sh case has
been done deliberately, but IMHO is not good, since code in /etc/bash.bashrc 
typically assumes that the full bash featureset is available, which is this 
case is a wrong assumption.  

If that kind of site-wide customisation is desired for sh shells it would be 
better to be implemented as an `ENV=/etc/sh.shrc ; export ENV' sequence of 
commands for the general sh case (so that it is also available for dash and 
possibly other shells). I attach a supplementary patch for that, in case you
find this possibility of interest (etc_profile-sh.shrc.patch).

regards
George Zarkadas

- -- System Information:
Debian Release: 6.0.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 
'stable'), (450, 'testing-proposed-updates'), (450, 'testing'), (400, 
'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/4 CPU cores)
Locale: LANG=el_GR.utf8, LC_CTYPE=el_GR.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages base-files depends on:
ii  gawk [awk]                1:3.1.7.dfsg-5 GNU awk, a pattern scanning and pr
ii  mawk [awk]                1.3.3-15       a pattern scanning and text proces

base-files recommends no packages.

base-files suggests no packages.

- -- no debconf information

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEbBAEBAgAGBQJOFLJsAAoJEJWXIVmJ5BwW5lMH+NoI/zYEH8cdzyVLk3rEKQgS
oEgJsGAssGP0RVtQ3j6rNSe7ySth3k0dDkMYosi46z3bE+ovWEqIeP894GI37MBu
UlEDho49D48G4d7wlZm9IXP1EziT7Wn1pWYWCfRWZcIEp3qHm6OAsmSOWkpSh29k
k7PQuYreAaPTAymK3+lAFsSoE/BeNGOWXzOnUuCbxVORMYo3ZOpwTvG3Sa1ueqYC
gRz+r9IpwpG69ZN7FSx5fQGBmO3mJ5mko1xFA7njPOFJKOg/mS8Afb0A3q+OKlRQ
7LPnc6TJpDBnJnQ1GAhu+rclvJYeeEFNnc3FOyEZDy7Dn55mUTtNHGzADVDFnQ==
=8EBj
-----END PGP SIGNATURE-----
--- /etc/profile        2010-08-06 20:42:50.000000000 +0300
+++ /etc/profile        2011-07-06 18:40:59.187069301 +0300
@@ -9,11 +9,16 @@
 export PATH
 
 if [ "$PS1" ]; then
-  if [ "$BASH" ]; then
-    # The file bash.bashrc already sets the default PS1.
-    # PS1='\h:\w\$ '
+  # When bash is called as sh it should behave as sh.
+  # Note that since bash enters posix mode after reading startup files,
+  # the only test that can be applied here is the value of $BASH.
+  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
     if [ -f /etc/bash.bashrc ]; then
+      # The file bash.bashrc already sets the default PS1.
       . /etc/bash.bashrc
+    else
+      # Get a sane default if bash.bashrc does not exist. 
+      PS1='\h:\w\$ '
     fi
   else
     if [ "`id -u`" -eq 0 ]; then

--- /etc/profile        2010-08-06 20:42:50.000000000 +0300
+++ /etc/profile        2011-07-06 18:40:59.187069301 +0300
@@ -22,6 +22,17 @@
       PS1='$ '
     fi
   fi
+
+  # Support a similar to bash.bashrc site-wide customisation
+  # for interactive shells for the plain bourne shell.
+  # We put it out of the bash/sh conditional so that it is available
+  # to users with a bash login shell when starting an interactive sh
+  # subshell.
+
+  if [ -f /etc/sh.shrc ]; then
+    ENV=/etc/sh.shrc
+    export ENV
+  fi
 fi
 
 # The default umask is now handled by pam_umask.

--- /dev/null   2011-07-06 18:40:59.187069301 +0300
+++ /etc/sh.shrc        2011-07-06 18:40:59.187069301 +0300
@@ -1,0 +1,4 @@
+# System-wide .shrc file for interactive sh(1) shells.
+
+# To enable the settings / commands in this file for login shells as well,
+# set "ENV=/etc/sh.shrc ; export ENV" in /etc/profile.

Reply via email to