FreeBSD sh not the only b0rked shell (was: checked CVS code tagged)

Matthias Andree matthias.andree at gmx.de
Tue Nov 26 01:27:59 CET 2002


Matthias Andree <matthias.andree at gmx.de> writes:

> I came across an interesting sh feature^Wbug on FreeBSD: /bin/sh -c
> "unset BLAH ; echo $?" prints 0, but using -ec rather than -c prints
> nothing. I. e. the "unset" builtin of FreeBSD's /bin/sh fails
> silently. Hard to track; I figured because unset LANG was executed, but
> unset LC_ALL not.
>
> I believe this warrants a FreeBSD PR (problem report a. k. a. bug report
> to GNATS).

Looking at the above some minutes later, I feel stupid now. Of course,
the proper test would have been with single quotes, and it is indeed
consistent -- and consistently wrong, see
http://www.opengroup.org/onlinepubs/007904975/utilities/unset.html

The IEEE predecessor, Single Unix Specification v2, already required the
same behaviour:
http://www.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_014_015

The list of shells that violate IEEE Std 1003.1-2001 is: bash (some
versions/OS), FreeBSD sh aka ash, pdksh, Solaris ksh.

Did I say this stinks? I mean, really stinks, like a festering pile of
dung? Why can't shells behave properly and consistently across systems?

Bugger them shell authors. They should check their facts before "fixing"
things that ain't broken. Send them hats to eat and brown paper bags and
a pair of scissors to hide.

I filed bug reports against GNU bash, FreeBSD sh, pdksh. I don't care
for zsh, it's too broken to bother with that anyways. I should file a
bug report against Solaris 8 ksh as well, but that's vain
endeavour. They would have replaced their /bin/sh by a fixed ksh long
ago if they'd cared.

Here are the fun files:

=== FREEBSD 4.7-STABLE ===

bash-2.05b.004  pdksh-5.2.14p2  zsh-4.0.6

$ set +x ; for i in `grep ^/ /etc/shells | grep -v csh` ; do echo $i: ; $i -e -c 'BONK= ; unset BONK ; unset BONK ; echo in $?' ; echo out $? ; done
/bin/sh:
out 1
/usr/local/bin/bash:
in 0
out 0
/usr/local/bin/zsh:
out 1
/usr/local/bin/ksh:
out 1
$ set +x ; for i in `grep ^/ /etc/shells | grep -v csh` ; do echo $i: ; $i -c 'BONK= ; unset BONK ; unset BONK ; echo in $?' ; echo out $? ; done
/bin/sh:
in 1
out 0
/usr/local/bin/bash:
in 0
out 0
/usr/local/bin/zsh:
in 1
out 0
/usr/local/bin/ksh:
in 1
out 0

=== SOLARIS 8 ===

(need to cater for /bin/sh not supporting -e, using set -e instead):
GNU bash, version 2.05.0(1)-release

$ set +x ; for i in /bin/sh /usr/bin/ksh /usr/local/bin/bash ; do echo $i: ; $i -c 'set -e ; BONK= ; unset BONK ; unset BONK ; echo in $?' ; echo out $? ; done
/bin/sh:
in 0
out 0
/usr/bin/ksh:
out 1
/usr/local/bin/bash:
out 1
$ set +x ; for i in /bin/sh /usr/bin/ksh /usr/local/bin/bash ; do echo $i: ; $i -c 'set +e ; BONK= ; unset BONK ; unset BONK ; echo in $?' ; echo out $? ; done
/bin/sh:
in 0
out 0
/usr/bin/ksh:
in 1
out 0
/usr/local/bin/bash:
in 1
out 0


-- 
Matthias Andree



More information about the bogofilter-dev mailing list