tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bug in sh, probably, with test case



One of the git tests fails.  I have reduced the failure to a small test
case:

----------------------------------------
#!/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}".)

Attachment: pgpF26yfDQ7ZG.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index