Ubuntu

Comment 30 for bug 61463

Jeff Schering (jeffsch) wrote :

According to the manpage for bash, when invoked with sh, bash is POSIX compliant. When you ask for /bin/sh, you get bash running in POSIX compliant mode. When you ask for /bin/bash you get bash running in its default mode.

To demonstrate, make sure your /bin/sh is symlinked to bash, then run these two scripts and compare their outputs.

script1
!#/bin/sh
kill -l

script2
!#/bin/bash
kill -l

So you can see that invoking bash with /bin/sh causes it to run in a POSIX compliant manner. (see http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html which describes the kill command in POSIX systems)

One of the two documented exceptions is in the way bash handles options to the built-in echo command (see /usr/share/docs/bash/POSIX.gz, scroll down to the bottom).

The reason for this is simple. Until IEEE Std 1003.1 2004 Edition, the spec said that POSIX compliant implementations of the shell "need not" support options. It appears that the ash developers decided to *not* support options to echo, while the bash developers decided to *allow* options to echo, for whatever reason. (for the spec on echo, see http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html)

The standard was changed in 2004 to specify that echo "shall not" accept options, leaving bash in a state not only of non-compliance, but also with a long list of shell scripts that depended on the echo command being able to accept options. So today, bash still accepts options to echo even when in POSIX compliance mode.

However, bash can be configured to be in complete conformance, ignoring options to the echo command. (see the manpage)

Generally though, the echo command is a headache for POSIX compliance. To quote the standard: "It is not possible to use echo portably across all POSIX systems unless both -n (as the first argument) and escape sequences are omitted."

Perhaps because of the non-portability of echo, the standard recommends this: "New applications are encouraged to use printf instead of echo."

But if new applications are encouraged to use printf instead of echo, then why is echo not deprecated? Again, a quote from the standard: "The echo utility has not been made obsolescent because of its extremely widespread use in historical applications."

Ideally, echo should be obsolete and all scripts should use printf instead. However, the large number of scripts using echo makes it impractical.

If the ISO standards people can keep echo around because of its extremely widespread use in the past, then why can't Ubuntu people keep bash around for the same reason? Afterall, as shown above, bash is POSIX compliant when run as sh.

The only advantage that dash has is its size and speed, but these are probably irrelevant to the overwhelming majority of Ubuntu users, who would almost never notice a speed difference between the two anyway. More important to them is to have "black boxes" (that's what a shell script is to normal people) that "just work".