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
?
2 Answers
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.
-
-
2but scripts with /bin/sh in the the shebang are not intended for bash, are they now?– user601Commented Sep 5, 2010 at 8:36
-
2@hop: They might not be intended for bash but they still may be tested only on bash. Commented 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 inbash
) should be considered broken. The simplest way to fix such scripts is to replace the shebang with#!/bin/bash
(or#!/usr/bin/env bash
).– jw013Commented 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 assh
. Otherwise, it simply won't work on any system that does not havesh
linked tobash
. The practical thing to do is to write and shebang your scripts correctly so they actually work.– jw013Commented Dec 18, 2011 at 3:34
Not even sh scripts are compatible with dash. Pkgsrc's bootstrap, par example.
-
1Interesting. 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 DCommented 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. Commented 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
Commented Dec 21, 2012 at 10:28
#!/bin/bash
and that his scripts aren't posix compliant and thus need to be specified to run with the proper interpreter