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.
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.
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.
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.
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 ...).
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).
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.
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 ;-)
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'.
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.
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.