7

Wikipedia says that dash executes faster than bash. My question is, if I set /bin/sh to dash, will all scripts that use /bin/sh in their shebang line that was intended for bash work under dash?

1
  • 8
    if they don't work you should yell at the author and tell him that the #! line should be #!/bin/bash and that his scripts aren't posix compliant and thus need to be specified to run with the proper interpreter Sep 5, 2010 at 3:00

2 Answers 2

12

No, not all scripts intended for bash work with dash. A number of 'bashism' will not work in dash, such as C-style for loops and the double-bracket comparison operators. If you have a set of bash scripts that you want to use for dash, you may consider using checkbashisms. This tool will check your script for bash-only features that aren't likely to work in dash.

7
  • Ooo. Handy utility Sep 5, 2010 at 2:36
  • 2
    but scripts with /bin/sh in the the shebang are not intended for bash, are they now?
    – user601
    Sep 5, 2010 at 8:36
  • 2
    @hop: They might not be intended for bash but they still may be tested only on bash. Sep 5, 2010 at 12:06
  • 2
    @MaciejPiechotka Any script that uses a shebang line of #!/bin/sh but doesn't work in /bin/sh (e.g. because it was written for and only runs in bash) should be considered broken. The simplest way to fix such scripts is to replace the shebang with #!/bin/bash (or #!/usr/bin/env bash).
    – jw013
    Dec 16, 2011 at 2:32
  • 1
    @MaciejPiechotka You miss my point. I didn't suggest that everyone should go and now and fix all the errors in scripts on their system. No one has time for that and if they already work, there are plenty of more urgent things to do. I'm just pointing out the undeniable fact that if you write a script that depends on bash-only features you should declare it as such and not as sh. Otherwise, it simply won't work on any system that does not have sh linked to bash. The practical thing to do is to write and shebang your scripts correctly so they actually work.
    – jw013
    Dec 18, 2011 at 3:34
-1

Not even sh scripts are compatible with dash. Pkgsrc's bootstrap, par example.

3
  • 1
    Interesting. I was under the impression that recent versions of dash are POSIX compliant. A quick check using dash -n didn't come up with any errors when run against bootstrap, but that is the most naive of tests.
    – Steven D
    Sep 5, 2010 at 6:54
  • @Steven IIRC there's one variable that dash doesn't support. Possibly more things, but the list is very small. Sep 5, 2010 at 14:24
  • dash is a port of NetBSD's sh to Debian, so it seems unlikely that it doesn't work for something that has been designed to work with NetBSD's sh. Ironically, that script is not POSIX conformant but is Debian conformant since it uses local Dec 21, 2012 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .