Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 18918 - /etc/profile assumes /bin/sh links to bash
Summary: /etc/profile assumes /bin/sh links to bash
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Martin Schlemmer (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-07 14:59 UTC by Björn Lindström
Modified: 2003-09-26 00:06 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch for `/etc/profile' to make it work for true a true POSIX `/bin/sh' (profile.patch,928 bytes, patch)
2003-04-24 23:51 UTC, James Michael Fultz
Details | Diff
patch for `/etc/profile' to make it work for a true POSIX `/bin/sh' (profile.patch,920 bytes, patch)
2003-04-25 06:36 UTC, James Michael Fultz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Lindström 2003-04-07 14:59:35 UTC
Since some people want to link /bin/sh to something other than /bin/bash (like
for instance /bin/ash) the lines reading:

if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]

should be replaced by something that actually checks if the shell is bash, such as:

if [ -z "$BASH" ]

as it is now, it makes the ash prompt look totally oogie.
Comment 1 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-08 15:25:51 UTC
Right, so we should only set PS1 if we are not using bash ?  If you change beyond
system defaults, you should know to change config files.

Comment 2 Björn Lindström 2003-04-08 16:22:23 UTC
The tests are obviously there to check if the shell is bash. As such they do not work. So, if you are not going to fix them, you might as well remove them.

Hell, checking $BASH is even more efficient, since it only has to use [ once.
Comment 3 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-08 17:56:36 UTC
1) Check FHS .. /bin/sh should be sh or a sh compadible replacement.  If ash
cannot handle PS1, meaning its not compadible to the original sh, then its not a
suitable replacement.

2)  Your $BASH check will fail if you use the original sh, or a 100% clone,
so its not valid.

If $SHELL is /bin/sh or /bin/bash, then FHS say I should be able to assume
that it should be a fully functional sh, or sh clone.  Meaning that if ash
do not fill these requirements, I do not see why I should change anything.
Comment 4 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-08 17:59:38 UTC
That last comment should be:

If $SHELL is /bin/sh, then FHS say I should be able to assume that it should be a
fully functional sh, or sh clone.  Meaning that if ash do not fill these
requirements, I do not see why I should change anything.  As bash is a 100%
clone, it is included in the check.

I do not stop you to use ash.  I dont however see why I should support a broken
setup (if ash do not handle our /etc/profile, what else might bork ...).
Comment 5 Björn Lindström 2003-04-09 01:07:30 UTC
Bash is not a 100% bourne shell clone. The handling of PS1 is one of the differences. Ash however, essentially is a bourne shell clone. I you want to have bash-specific stuff in the default setup it should go in /etc/bashrc.

I am a bit bothered that Gentoo does not honour this, so I am filing bug reports about those few scripts that use /bin/sh assuming it is bash. In every case except /etc/profile this means changing #!/bin/sh to #!/bin/bash, so it's really easy to fix this issue (I actually think I'm already done).
Comment 6 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-09 18:02:18 UTC
If bash is started as 'sh', then it conforms to posix standards for sh.  It
works fine with the PS1 as we set it, meaning it conforms to posix standards.
Seemingly ash do not conform to posix standards?

From the bash manual:

----------------------------------------------------

       If  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.  When invoked as an interac-
       tive login shell, or a non-interactive shell with the  --login  option,
       it  first  attempts  to read and execute commands from /etc/profile and
       ~/.profile, in that order.  The  --noprofile  option  may  be  used  to
       inhibit  this  behavior.  When invoked as an interactive shell with the
       name sh, bash looks for the variable ENV, expands its value  if  it  is
       defined,  and uses the expanded value as the name of a file to read and
       execute.  Since a shell invoked as sh does not attempt to read and exe-
       cute  commands from any other startup files, the --rcfile option has no
       effect.  A non-interactive shell invoked with  the  name  sh  does  not
       attempt  to  read  any  other  startup files.  When invoked as sh, bash
       enters posix mode after the startup files are read.

       When bash is started in posix mode, as with the  --posix  command  line
       option, it follows the POSIX standard for startup files.  In this mode,
       interactive shells expand the ENV variable and commands  are  read  and
       executed  from  the  file  whose  name is the expanded value.  No other
       startup files are read.
Comment 7 Björn Lindström 2003-04-10 01:01:30 UTC
You are misunderstanding the situation. bash, called as /bin/sh, is supporting a _superset_ of the POSIX shell syntax.

Anyway, I'm not asking you to remove the PS1 setting from /etc/profile, only to make the test to see if the shell is bash work correctly, and at the same time faster. To make it absolutely crystal clear, you will get the advantage of a POSIX compliant /etc/profile, without any disadvantages.

By the way, the ash manual is a actually a pretty good place to look if you want to look up what is bourne shell compliant and not. (The bash manual might not be such a good place for that ;-)
Comment 8 James Michael Fultz 2003-04-24 23:51:58 UTC
Created attachment 11098 [details, diff]
patch for `/etc/profile' to make it work for true a true POSIX `/bin/sh'

I've tested this successfully with both Bash and pdksh including `/bin/sh'
symlinked to `/bin/bash', and `/bin/sh' symlinked to `/bin/ksh'.
Comment 9 James Michael Fultz 2003-04-25 06:36:53 UTC
Created attachment 11118 [details, diff]
patch for `/etc/profile' to make it work for a true POSIX `/bin/sh'

This patch supercedes by previous patch by replacing the `/usr/bin/whoami'
command substitution with the `LOGNAME' environment variable which is set by
login(1) to the user's login name. Efficiency is increased by removing the
execution of an unnecessary external command.
Comment 10 Martin Schlemmer (RETIRED) gentoo-dev 2003-04-27 12:58:16 UTC
Ok, fixed on cvs.

The 'source /etc/profile.env' have been fixed some time ago.  The LOGNAME change
looks good.  Changed the 'if [ "$BASH" ]' check to 'if [ -n "$BASH" ]' though,
as it is better form.