Date: Wed, 18 Mar 2009 13:13:25 +0100 (CET) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-standards@FreeBSD.ORG Subject: Suspecting bug in /bin/sh's IFS Message-ID: <200903181213.n2ICDPpT042350@lurza.secnetix.de>
next in thread | raw e-mail | index | archive | help
Hello,
According to the sh(1) manpage and the SUSv3 wording, the
order of characters in the IFS variable should not matter
for field splitting. However, I get strange results with
our /bin/sh ...
I'm trying to parse config files that look like this:
ip = 10.1.2.3
host = some.name
desc = some description here
That is, the format of lines is this:
<key> <whitespace>* "=" <whitespace>* <value>
Of course that should be simple: Just add "=" to $IFS
and read the lines in a loop, like the following (the
echo command is for debugging; the real shell code uses
the setvar command instead):
IFS="=$IFS"
while read key val; do
echo "'$key' -- '$val'"
done < config
However, the "=" characters and some spaces are included
in $val, which is wrong behaviour, I think. I get this
output:
'ip' -- ' = 10.1.2.3'
'host' -- '= some.name'
'desc' -- '= some description here'
If I change the IFS line like this (diff -u format):
- IFS="=$IFS"
+ IFS="$IFS="
then I get the correct and expected output:
'ip' -- '10.1.2.3'
'host' -- 'some.name'
'desc' -- 'some description here'
Note that the characters in IFS are exactly the same, only
the order is different.
On Solaris, the same shell script produces correct output
in both cases, independent from the order of characters
in IFS. I've also tested zsh and bash: They also produce
correct output in both cases.
So this really seems to be a bug in FreeBSD's /bin/sh.
I'm about to file a PR, but I suppose it's better to ask
the standards mailinglist first, so here I am.
Best regards
Oliver
--
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart
FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903181213.n2ICDPpT042350>
