dash as /bin/sh, and now ld –as-needed. Pattern?

I must admit that I’ve never been a big fan of the dash as /bin/sh change. I have three main problems with the switch:

POSIX compliance as an argument

Complying to standards is a really good thing. But when everybody is ignoring the standard because they want the comfort of newer features, maybe it’s a sign that the standard should be updated to include those newer features. Most of the bashims used everywhere in scripts were signifiant improvements, like the ability to write:
cp {short1/path1,short2/path2}/very/long/common/path/to/a/file
instead of:
cp short1/path1/very/long/common/path/to/a/file short2/path2/very/long/common/path/to/a/file

The option to improve bash was not fully explored

We started with the premise that bash is bloated, slow, and cannot be improved. Maybe you can help me with that, but I could only find a few simplistic benchmarks comparing dash and bash, and I could not find any analysis of why bash is slow, and why it cannot be improved.
One of the obvious problems is that bash is also an interactive shell, and is linked to ncurses and terminfo, which increases the startup time. But have we investigated the possibility to have a /bin/bash-non-interactive binary that would not be linked to ncurses?

The change was brought to users

While it is OK for Debian (or Ubuntu, in that case, since that change was done in Ubuntu first) to force its developers to use POSIX-compliant scripts, the switch could have been made only to Debian-created scripts (by switching them from a /bin/sh shebang to a /bin/dash shebang, for example). I have trouble justifying that this change was forced on users as well.

Next: linker changes

… and we are doing it again. A set of linker changes (see also the Ubuntu page) was already done in Ubuntu, and is very likely to be done in Debian as well. This switch requires deep changes in some buildsystems (it requires ordering of libraries and forbids indirect dependencies), and is rather painful (it was reverted before the Ubuntu 11.04 release because it was not possible to fix all the packages during the natty release cycle, but is done in the 11.10 release). Of course, there are justifications for this change. But I’m not sure that it’s worth all the trouble created for users.

18 thoughts on “dash as /bin/sh, and now ld –as-needed. Pattern?

  1. The interesting thing is if taking a look at the bigger picture the only shell which is really there on _every_ plattform is bash, not dash (not only linux, but solaris, *bsd, aix, …)
    So in the end every bashism report on my software is simply fixed by using #!/bin/bash.

    Another point not mentioned is, that IMHO with all those new dash scripts it got SLOWER, not faster because with dash many tasks require you to pipe text through awk/sed/grep/… instead of just doing it in process.
    BUT with systemd all those shellscript foo is hopely going to die a slow death…

    Imho dash scripts really only make sense if scripts that are also needed in initramfs.

  2. Using dash as /bin/sh does improve performance, but that only really matters for boot time; any other time the performance of shell scripts rarely represents the bottleneck.

    So, personally, I’d rather see Debian switch to systemd, kill off the use of shell scripts at boot time, and then use bash as /bin/sh again. :)

  3. While I’ll agree that alternatives to rewriting a whole shell from scratch should have been explored better, the whole #!/bin/sh business means that you should have been writing POSIX-compliant scripts from the start, and this isn’t just about Dash. I’ve written a number of #!/bin/sh scripts on an OpenEmbedded based system that uses busybox’s ash as its default shell, and could not use many of the Bash extensions.

    In a nutshell, if you want Bash, use Bash. Don’t pretend that you want something else, under the pretext that “it works on most systems anyway.”

  4. The interesting thing is if taking a look at the bigger picture the only shell which is really there on _every_ plattform is bash, not dash (not only linux, but solaris, *bsd, aix, …)
    So in the end every bashism report on my software is simply fixed by using #!/bin/bash.

    Nope, none of *bsd has bash by default. Even if it’s installed, it won’t be in /bin but somewhere else (usually either /usr/pkg/bin or /usr/local/bin).

  5. I’ve adjusted to the POSIX shell since many years now: the only thing I’m still missing is arrays, and even they can be approximated by an eval-fest.

    To be honest though when it starts feeling like an {eval,fork}-fest, it’s usually time to switch to a “real” scripting language.

    As the previous posters said, “#! /bin/bash” works fine if you can’t be bothered to adjust. You’d better make sure you don’t use e.g. Bash 4 features when one of your target platforms only has Bash < 4 preinstalled.

    As for the {str1,str2} expansion, it’s more of a gimmick, and usually indicates you’re hardcoding too much stuff in your script.

    Case in point:

    $ echo $BASH_VERSION
    4.2.10(1)-release
    $ a=1
    $ b=2
    $ echo c{$a,$b}
    c1 c2
    $ echo {$a,$b}c # Parser fail

    $ echo {${a},${b}}c
    1c 2c

    PS: Please enable comment previews!

  6. It would be possible to build Debian packages with –as-needed without changing the default behavior of gcc by putting -Wl,–as-needed in $(dpkg-buildflags –get LDFLAGS).

  7. Interesting blog entry.
    In my opinion, most of your points can be explained by “The CADT Model”, a term coined by JWZ.

  8. IIUC the linker change has been implemented in RHEL6 as well and is indeed quite annoying (possibly requiring conceptual changes for build systems and releases). And I think the new behavior is already the default on Solaris 10 (and was quite annoying there too). So maybe the necessary build system fixes will be made anyway, and it won’t be that bad for Debian and Ubuntu.

    Btw. is “CADT” this week’s meme? That’s now the second time today I see this term (this accusation) in a blog comment…

  9. OMG!!! i think he read this blog last nite
    he really loves that shirt
    as rain said before he wants to bring her GF in the army
    he cant bring her but he bringing her name on him

  10. Thank you for sharing superb informations. Your web-site is very cool. I’m impressed by the details that you have on this web site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found just the info I already searched everywhere and just could not come across. What a great web-site.

  11. I got what you mean , thankyou for putting up.Woh I am pleased to find this website through google. “Money is the most egalitarian force in society. It confers power on whoever holds it.” by Roger Starr.

  12. Hi there, I found your website via Google even as looking for a comparable matter, your site came up, it seems to be good. I have bookmarked it in my google bookmarks.

  13. Thank you a tremendous post, would read your particular others content. thanks for your thoughts for this, I felt a lttle bit strike by this article. Thanks again! You wanna make a great aspect. Has fantastic report here. I feel if a greater number of people consideration for it that way, they’d have a better time have the hold ofing the issue.

  14. Do you mind if I quote a few of your posts as long as I provide credit and sources back to your weblog? My website is in the very same area of interest as yours and my visitors would genuinely benefit from some of the information you present here. Please let me know if this alright with you. Thanks!

Comments are closed.