tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bug in sh, probably, with test case
On 2012-12-20 14:22, Greg Troxel wrote:
One of the git tests fails. I have reduced the failure to a small test
case:
I too have noticed this bug. This is the test case I used:
sh -c 'a="x x"; unset b; printf %s\\n "${b-${a}}"'
Notice the two spaces between the two exes (to confirm that it's not
doing field splitting).
It should print:
x x
but on NetBSD it prints:
x
x
-Richard
----------------------------------------
#!/bin/sh
func() {
n=$1; shift
echo "$n 1 <$1>"
echo "$n 2 <$2>"
}
p="--foo --bar"
func bare $p
func quoted "$p"
func alt "alt ${p:+$p}"
----------------------------------------
I get results (netbsd-5, i386)
sh:
----------------------------------------
bare 1 <--foo>
bare 2 <--bar>
quoted 1 <--foo --bar>
quoted 2 <>
alt 1 <alt --foo>
alt 2 <--bar>
----------------------------------------
bash:
----------------------------------------
bare 1 <--foo>
bare 2 <--bar>
quoted 1 <--foo --bar>
quoted 2 <>
alt 1 <alt --foo --bar>
alt 2 <>
----------------------------------------
ksh:
----------------------------------------
bare 1 <--foo>
bare 2 <--bar>
quoted 1 <--foo --bar>
quoted 2 <>
alt 1 <alt --foo --bar>
alt 2 <>
----------------------------------------
and obviously the Linux shells do not split the contents of $p, because
the git tests must pass there.
POSIX requires that field splitting not be done on the results of
substitutions in "":
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
so I think our sh is wrong.
(git's test is constructing a human-readable string explaining the
arguments passed to the test, so it is doing essentially like the 'alt'
line above, but with extra text: "....is valid${2:+ with options $2}".)
Home |
Main Index |
Thread Index |
Old Index