dash as #!/bin/sh introduces countless incompatibilities
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dash (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: dash
Hi,
I understand the rationale of using a lightweight bourne shell clone for #!/bin/sh instead of bash, however Ubuntu's use of dash as #!/bin/sh by default has broken countless scripts and brought us back into the dark ages of platform-specific scripting. Bashisms and various unixy #!/bin/sh variant quirks are well understood in their incomatabilites (especially by the autoconf/
Software vendors, open source projects and even the ubuntu BTS are flooded with bugs that stem from dash incompatabilites, which are often hard to debug the root cause of. Examples:
https:/
https:/
https:/
https:/
https:/
This is not a duplicate bug report - it the a compound of all the above bugs that
Examples of 3rd party apps that break:
the ATI installer, vmWare, Xen, Mathematica, NX Server, MKS, NVC and anything else that relies on a sane #!/bin/sh
The scope of this problem is rather large. It would be reasonable to say "fix the scripts" if the scripts were buggy, but alas this is not the case.
The following code snippets are extracted from live, working scripts that are used frequently, that work in other versions of #!/bin/sh, but break in dash:
$ dash -c 'cnt=6; while [ $((cnt = cnt - 1)) -gt 0 ]; do echo $cnt; done'
dash: arith: syntax error: "cnt = cnt - 1"
$ dash-c 'if false; then d="${foo/bar}"; fi'
dash: Syntax error: Bad substitution
$ dash -c 'a=water;echo ${a:2:2}'
dash: Syntax error: Bad substitution
$ dash -c 'exec 20<&0'
exec: 1: 20: not found
$ dash -c 'echo $UID'
# no output. how on earth are we supposed to safely and portably get the UID?
$ dash -c 'echo hello 2>&1>/dev/null'
dash: Syntax error: redirection unexpected
$ dash -c 'x="1 2"; local y=$x; echo $y'
local: 1: 2: bad variable name
And an example from makeself:
shh.sh:
#!/bin/sh
tmpfile=foo
tmpdir=/tmp/dashtmp
mkdir "$tmpdir"
( cd "$tmpdir" && ( tar cvf - . | eval "gzip -c9" ) >> "$tmpfile" ) || { echo "Failed"; exit 1; }
echo >> "$tmpfile" >&-
$ ./shh.sh
./
./foo
./shh: line 6: echo: write error: Bad file descriptor
I invite others to collect similar examples here. If Ubuntu will not fix dashisms then we must support dash, which is why a compilation of incompatabilities is necessary, so that a list of workarounds can be put together, à la http://
The scripts *are* buggy. dash is POSIX-compliant, so all POSIX-compliant scripts will work with it. If they use bash-specific features, they must specify that they are to be executed by /bin/bash, rather than a general POSIX-compliant shell.